欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

spring boot2.0 自定义配置取值问题解决

程序员文章站 2022-07-12 22:07:04
...

 

 在yml里面配置

staticcode: 
  prefixUrl: https://s.zokoo.cn/qr/

 

在java取值:

@Configuration
@ConfigurationProperties(prefix = "staticcode")
@Data
public class StaticCodeConfig {
	
	private String prefixUrl;
}
//注意 需要提供 set get 这里用 lombok  

 

 

总结:直接把prefixUrl  当成 属性,名字不变

 

如果  @Value("${prefixUrl}")

        private String url;  这样不行