我正在使用Spring Boot应用程序.在某些@Component
类@Value
字段中加载,而不是在其他类上null
.
似乎在创建/ @Value
之后加载了.@Bean
@Component
我需要从我的属性文件中加载一些值@Bean
.
你有什么建议吗?
我是Spring新手,我想知道在Spring中使用@Value注释的先决条件/条件是什么?
我现在拥有的是一个Token类,它将硬编码的密钥作为字段.我想要做的是将此密钥移动到配置文件以消除硬编码但由于某种原因以下不起作用.
public class Token {
//...some code
@Value("${my.secretKey}")
private String key;
//...some code
}
Run Code Online (Sandbox Code Playgroud)
也许有任何标准技术来解决这类任务.
感谢帮助!
ps我有.properties
包含my.secretKey=123
条目的文件.