1.在yml配置文件以这样的格式写:
demo:
key111: 121212
2.类中用 @Component 和 @ConfigurationProperties注解,并且给这个变量弄一个非静态的set方法,就可以啦
@Component
@ConfigurationProperties(prefix = "demo")
class Test11{
private static String key111;
public static String getKey111() {
return key111;
}
public void setKey111(String key111) {
Test11.key111 = key111;
}
}
本文介绍如何在Spring Boot应用中使用YML配置文件进行属性设置,并通过@ConfigurationProperties注解将配置属性绑定到自定义Java类。具体步骤包括在YML文件中定义属性,创建带@Component和@ConfigurationProperties注解的类,以及实现set方法来接收属性值。
2918

被折叠的 条评论
为什么被折叠?



