简体   繁体   中英

Spring @PropertySource value not overridding

In my sprint boot application, I have a configuration class to read property files: common.properties and dev.properties . I have the same key server.url in both the property files. The value is not overridden. As per the spring documentation, the last property file value should be taken. But it's not working. I am using the spring annoatation @PropertySource to read values.

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. I tried changing the order, but still it's not working.

您需要在 application.properties 文件中添加您的活动配置文件

spring.profiles.active=dev

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM