I have a spring java class like below
@Getter
@Setter
@ConfigurationProperties(prefix = "check.connection")
public class MyConnection{
private String url;
private String key;
}
Below is my content of my default yml file (containing url and key),
check.connection.url = www.test.com
check.connection.key = DEFAULTKEY
check.connection.key.integration = INTEGRATIONENVKEY
Problem Statement : I want to map 'key' in my java class with 'check.connection.key.integration' when application is running on integration env. and in all other envs, it should be mapped to 'check.connection.key'. I know I have to use @Profile and @value somehow in MyConnection.java file, but not able to identify exact syntax.
Based on above code (@ConfigurationProperties), in all env,'key' is getting mapped to 'check.connection.key', which I dont want for Integration environment.
The
@ConfigurationPropertiesannotation is used to map a class properties with a configuration file properties. Here you don't need to call@Valuebecause Spring will automatically configureMyConnectionto map with your properties in theapplication.propertiefile.There are some modifications you have to do in your class:
@Configurationon your classkeyIntegrationto map it with your file propertiecheck.connection.key.integrationFor more details, check this link.