[英]Spring @PropertySource value not overridding
在我的 sprint 启动应用程序中,我有一个配置类来读取属性文件: common.properties
和dev.properties
。 我在两个属性文件中都有相同的密钥server.url
。 该值不会被覆盖。 根据 spring 文档,应采用最后一个属性文件值。 但它不起作用。 我正在使用 spring 注释@PropertySource
来读取值。
服务器配置类
@Component
@PropertySources(
{
@PropertySource(value = "file:Common/config/common.properties", ignoreResourceNotFound = true),
@PropertySource(value = "file:Dev/config/dev.properties", ignoreResourceNotFound = true)
})
public final class ServerConfiguration {
private final ApplicationContext applicationContext;
/**
* The Server URL
*/
@Value("${server.url}")
private String serverUrl;
}
公共属性
server.url=ws://some ip
开发属性
server.url=ws://localhost:8080
始终采用common.properties
的值。 我尝试更改顺序,但仍然无法正常工作。
您需要在 application.properties 文件中添加您的活动配置文件
spring.profiles.active=dev
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.