@value注入失败问题?

项目结构如图,auth是权鉴相关的包,无启动类,配置文件在user模块中

1、使用了compent注解

2、被注入的是静态属性,是通过set方式注入

@Component
public class JwtUtil {

    /**
     * JWT认证加密私钥(Base64加密)
     */
    private static String encryptJwtKey;

    @Value("${config.encrypt-jwtKey}")
    public void setEncryptJwtKey(String encryptJwtKey) {
        JwtUtil.encryptJwtKey = encryptJwtKey;
    }

 

@Value("${config.encrypt-jwtKey}")

private static String encryptJwtKey;

 

写成这样的就可以了

@Value作用在属性上,不是作用在方法上的

@Value("${config.encrypt-jwtKey}")

private static String encryptJwtKey;

这样直接就注入了,如果不行,把static去掉