当前位置:网站首页>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注解
边栏推荐
- The sales volume could not catch up with the speed of taking money. Weima went to Hong Kong for emergency rescue
- Canonical的工程师们正努力解决Firefox Snap的性能问题
- 习题8 #第8章 Verilog有限状态机设计-4 #Verilog #Quartus #modelsim
- 以其他组件为代价的性能提升不是好提升
- Lingyun going to sea | Wenhua online &huawei cloud: creating a new solution for smart teaching in Africa
- From CIO to Consultant: the transformation of it leaders
- 程序员值得收藏的几款代码截图美化工具播
- Intégration d'outils et de cadres tiers
- 终于,进亚马逊了~
- MSYQL, redis, mongodb visual monitoring tool grafana
猜你喜欢

开发者任务中心上线!千元豪礼送不停!

程序员值得收藏的几款代码截图美化工具播

What about frequent network disconnection of win11 system? Solution to win11 network instability

After CDN is added to the website, the Font Icon reports an error access control allow origin

Escape and March, the "two-sided Jianghu" of temporary food

以其他组件为代价的性能提升不是好提升

@Sneakythlows annotation

How to install and use computer SSD hard disk

KDD 2022 | 协同过滤中考虑表征对齐和均匀性

Kdd 2022 | prise en compte de l'alignement et de l'uniformité des représentations dans le Filtrage collaboratif
随机推荐
After CDN is added to the website, the Font Icon reports an error access control allow origin
数据库是什么?数据库详细笔记!带你走进数据库~你想知道的这里都有!
layer. prompt
CAD Assistant - 3D模型格式转换利器
TP5 where queries whether a field in the database contains a value. Fuzzy queries are performed without the like method
Exploration and practice of NLP problem modeling scheme
凌云出海记 | 文华在线&华为云:打造非洲智慧教学新方案
docker compose 部署Flask项目并构建redis服务
JVM(4) 字节码技术+运行期优化
Sophomore majoring in software engineering, the previous learning situation is not very good. How to plan the follow-up development route
有了这4个安全测试工具,对软件安全测试say so easy!
Flutter 2.0 FocusScope. of(context). The requestfocus (focusnode()) does not take effect
KDD 2022 | 協同過濾中考慮錶征對齊和均勻性
From CIO to Consultant: the transformation of it leaders
[proteus simulation] matrix keyboard interrupt scanning
ovirt数据库修改删除节点
4-2 port banner information acquisition
Violent solution to the question of guessing the ranking
Win11系统小组件打不开?Win11系统小组件无法打开解决方法
powershell命令仅输出目录列表