Krishnanunni P V
Krishnanunni P V

Reputation: 699

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.

Upvotes: 4

Views: 538

Answers (1)

Amir Serry
Amir Serry

Reputation: 326

you need to add in the application.properties file your active profile

spring.profiles.active=dev

Upvotes: 3

Related Questions