I normally configure the applicationContext using Annotation based configuration rather than XML based configuration. Anyway, I believe both of them have the same priority.
*Answering your question, system variable has higher priority *
@Component
@Profile("dev")
public class DatasourceConfigForDev
Now, the profile is dev
Note : if the Profile is given as
@Profile("!dev")
then the profile will exclude dev and be for all others.
<beans profile="dev">
<bean id="DatasourceConfigForDev" class="org.skoolguy.profiles.DatasourceConfigForDev"/>
</beans>
@Configuration
public class MyWebApplicationInitializer implements WebApplicationInitializer {
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
servletContext.setInitParameter("spring.profiles.active", "dev");
}
}
@Autowired
private ConfigurableEnvironment env;
// ...
env.setActiveProfiles("dev");
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/app-config.xml</param-value>
</context-param>
<context-param>
<param-name>spring.profiles.active</param-name>
<param-value>dev</param-value>
</context-param>
The profile names passed as the parameter will be activated during application start-up:
-Dspring.profiles.active=dev
In IDEs, you can set the environment variables and values to use when an application runs. The following is the Run Configuration in Eclipse:
to set via command line : export spring_profiles_active=dev
Any bean that does not specify a profile belongs to “default” profile.