I am trying to determine the environment that the application is in but using the environment variable that Weblogic sets at startup via this line:
-Denvironment=DEV
I have a configuration class below:
package ie.gov.agriculture.cds;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
@Configuration
@PropertySource("classpath:application.properties")
public class AppConfig {
@Value("${environment}")
private String env;
@Bean
public static PropertySourcesPlaceholderConfigurer propertyConfigInDev() {
return new PropertySourcesPlaceholderConfigurer();
}
}
In the application.properties, if I define the property "environment", then it seems to work, but this is not what I want to achieve. It appears that I need to replace the PropertySource annotation value with something that will point to the weblogic server?
Any help would be much appreciated!
So the solution is that I was missing the property in my weblogic server configuration which is why it was not being picked up.
Inside the domains\%APPCODE%\bin folder of my weblogic server, in the setDomainEnv.cmd file, I included the environment property.
set JAVA_OPTIONS=-Dssoautologin.appcode=%APPCODE% -Denvironment=DESKTOP
This can then be picked up by Spring using the @Value("${environment}")
annotation.
Hope this helps someone else!