当前位置:网站首页>static静态成员变量使用@Value注入方式
static静态成员变量使用@Value注入方式
2022-06-29 19:19:00 【金箍一梦何来愁】
使用@Value 注解static类型
@Component
public class MyConfig {
@Value("${env}")
private static String env;
public static String getEnv() {
return env;
}
public static void setEnv(String env) {
MyConfig.env = env;
}
}
使用上面这种方式,MyConfig.getEnv()会返回null
正确写法
@Component
public class MyConfig {
private static String env;
public static String getEnv() {
return env;
}
@Value("${env}")
public void setEnv(String env) {
MyConfig.env = env;
}
}
一定是在非静态方法setEnv前使用@Value注解
边栏推荐
- 3-3 host discovery - layer 4 discovery
- 深度好文 | YOLOv5+DeepSORT多目标跟踪深入解读与测试(含源码)
- 3-3主机发现-四层发现
- STM32CubeMX 学习(6)外部中断实验
- 洞见科技作为「唯一」隐私计算数商,「首批」入驻长三角数据要素流通服务平台
- 高能直播,大咖云集!邀你共启BizDevOps探索之路。
- ArrayList< Integer> Use = = to compare whether the values are equal, and -129=- 129 situation thinking
- 领先11%,华为云天筹AI求解器再度登顶国际权威榜单
- The sales volume could not catch up with the speed of taking money. Weima went to Hong Kong for emergency rescue
- Technical methodology of new AI engine under the data infrastructure upgrade window
猜你喜欢
随机推荐
出逃与进军,临期食品的「双面江湖」
Win11 system component cannot be opened? Win11 system widget cannot be opened solution
C语言数组专题训练
74. maximum profit on shares
tp5 where查询数据库中的某个字段是否包含某个值,不用like的方法,模糊查询
揭秘!付费会员制下的那些小心机!
TP5 where queries whether a field in the database contains a value. Fuzzy queries are performed without the like method
习题8 #第8章 Verilog有限状态机设计-4 #Verilog #Quartus #modelsim
Element waiting mechanism
ArrayList<Integer>使用==比较值是否相等出现 -129!=-129的情况思考
Docker compose deploy the flask project and build the redis service
MBA-day19 如果p则q矛盾关系p 且非q
创作者基金会 6 月份亮点
【Proteus仿真】矩阵键盘中断扫描
Solution of portable emergency communication system for flood control and rescue
凌云出海记 | 文华在线&华为云:打造非洲智慧教学新方案
为什么信息化 ≠ 数字化?终于有人讲明白了
Shell bash script note: there must be no other irrelevant characters after the escape character \ at the end of a single line (multi line command)
4-2端口Banner信息获取
以其他组件为代价的性能提升不是好提升








![[笔记]再笔记--边干边学Verilog HDL –008](/img/7f/0ca73446247455ac4d8f9667083a87.png)
