[英]Spring @PropertySource value not overridding
In my sprint boot application, I have a configuration class to read property files: common.properties
and dev.properties
.在我的 sprint 启动应用程序中,我有一个配置类来读取属性文件: common.properties
和dev.properties
。 I have the same key server.url
in both the property files.我在两个属性文件中都有相同的密钥server.url
。 The value is not overridden.该值不会被覆盖。 As per the spring documentation, the last property file value should be taken.根据 spring 文档,应采用最后一个属性文件值。 But it's not working.但它不起作用。 I am using the spring annoatation @PropertySource
to read values.我正在使用 spring 注释@PropertySource
来读取值。
ServerConfiguration class服务器配置类
@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;
}
common.properties公共属性
server.url=ws://some ip
dev.properties开发属性
server.url=ws://localhost:8080
The value from common.properties
is taken always.始终采用common.properties
的值。 I tried changing the order, but still it's not working.我尝试更改顺序,但仍然无法正常工作。
您需要在 application.properties 文件中添加您的活动配置文件
spring.profiles.active=dev
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.