I'm trying to get active profile from application.properties file during "maven install". I tried to;
@Value("${spring.profiles.active}")
String activeProfiles;
however, it returns null.
Here is the related part from the application.properties;
#PROFILE SETTINGS
spring.profiles.active=@spring.profiles.active@
Any ideas ?
EDIT:
Here are the classes I'm trouble with in;
The class I'm trying to get active profile;
public class JdoProperties {
@Value("${spring.profiles.active}")
String activeProfiles;
public Properties getProperties() {
Properties properties = new Properties();
try {
if(activeProfiles.contains("test")) {
properties.load(new ClassPathResource("application-test.properties").getInputStream());
} else if(activeProfiles.contains("dev")) {
properties.load(new ClassPathResource("application-dev.properties").getInputStream());
} else if(activeProfiles.contains("prod")) {
properties.load(new ClassPathResource("application-prod.properties").getInputStream());
}
} catch(FileNotFoundException e) {
System.out.println("FileNotFound " + e);
} catch(IOException e) {
//TODO: Logger
System.out.println("IOException " + e);
}
return properties;
}
}
The class I'm trying to use that profile
public final class PMF
{
private PMF() {}
public static PersistenceManagerFactory getPersistenceManagerFactory() {
JdoProperties jdo_properties = new JdoProperties();
Properties properties = jdo_properties.getProperties();
return JDOHelper.getPersistenceManagerFactory(properties);
}
}
The class that use PMF class;
@Configuration
@Import({ShiroBeanConfiguration.class,
ShiroAnnotationProcessorConfiguration.class,
ShiroWebConfiguration.class,
ShiroWebFilterConfiguration.class})
public class RealmConfig{
...
@Bean
@DependsOn("lifecycleBeanPostProcessor")
public Realm realm() {
DataSource dataSourceMySQL =
(DataSource) PMF.getPersistenceManagerFactory()
.getConnectionFactory();
JdbcRealm jdbcRealm = new JdbcRealm();
jdbcRealm.setCredentialsMatcher(new PasswordMatcher());
jdbcRealm.setAuthenticationQuery(AUTHENTICATION_QUERY);
jdbcRealm.setUserRolesQuery(USER_ROLES_QUERY);
jdbcRealm.setPermissionsQuery(PERMISSIONS_QUERY);
jdbcRealm.setDataSource(dataSourceMySQL);
return jdbcRealm;
}
...
}
And the error I'm getting;
Caused by: java.lang.NullPointerException
at com.oe.dr.dream.data.JdoProperties.getProperties(JdoProperties.java:28)
at com.oe.dr.dream.data.PMF.getPersistenceManagerFactory(PMF.java:14)
at com.oe.dr.dream.config.RealmConfig.realm(RealmConfig.java:94)