在我的 sprint 启动应用程序中,我有一个配置类来读取属性文件:common.properties
和 dev.properties
。我在两个属性文件中都有相同的 key 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;
}
common.properties
server.url=ws://some ip
dev.properties
server.url=ws://localhost:8080
始终采用common.properties
中的值。我尝试更改顺序,但仍然不起作用。
最佳答案
您需要在 application.properties 文件中添加您的 Activity 配置文件
spring.profiles.active=dev
关于java - Spring @PropertySource 值不覆盖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40526820/