-
读取主配置文件(application.yml/application.properties)
-
@Value注解
@Value("${server.port}") public String port;
-
@ConfigurationProperties注解(需要为属性提供set方法)
@Component //指定实体类与配置项映射的前缀 @ConfigurationProperties(prefix = "server") public class IServer { public String port; public void setPort(String port) { this.port = port; } }
-
-
读取自定义配置文件
-
@PropertySource + @Value
//指定resources目录下的自定义配置文件(可指定多个) @PropertySource(value = {"classpath:weather.properties"}) @Value("${weather.url}") String weatherUrl;
-
@PropertySource + @ConfigurationProperties(需要为属性提供set方法)
@Component @PropertySource(value = {"classpath:weather.properties"}) @ConfigurationProperties(prefix = "weather") public class Weather { public String url; public void setUrl(String url) { this.url = url; } }
-
05-30
1618
07-26
1034
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交