The spring profile is a concept introduced in Spring 3, which prefers to use the profile in Maven to differentiate between different environmental profiles. Spring's profile has not been used very much, and recently colleagues used spring profiles during a company's system development. But there was trouble setting up the default profile. After studying for a long time, we found the problem.
The use of Spring profile in our system is very simple and does not use the runtime feature, but defines the beans in different profile environments in XML
<!--other beans-->
<bean id= "Validator" class= " Org.springframework.validation.beanvalidation.LocalValidatorFactoryBean "/>
..... <!--production environment-->
<beans profile= "Production" >
<context:property-placeholder Ignore-resource-not-found= "true"
location= "classpath*:/application.properties"/>
....
</beans>
<!--local environment-->
<beans profile= "local" >
<context:property-placeholder Ignore-resource-not-found= "true"
location= "Classpath*:/application.properties
, classpath*:/ Application.development.properties "/>
.... </beans>
Then we can generally choose what environment profile to use in Web.xml, in properties, for example
<!--web.xml-->
<context-param>
<param-name>spring.profiles.default</param-name >
<param-value>production</param-value>
</context-param>
<!--properties Selection- ->
system.setproperty ("spring.profiles.active", "development");
Where are our problems? We want to choose the default profile by Jndi instead of JVM parameters, first we know that the settings for spring profile are not in the properties file because of the order in which spring is loaded. We do not want to change the system's startup parameters, so we chose the jndi way to read the default boot of profile, the key is here, we made the following settings when configuring Jndi
<environment name= "spring.profiles.active" type= "java.lang.String" value= "local" >
The sad discovery didn't work, and spring's log didn't have any useful hints, not yet to get profile-related log because the bean was not read. I had to get rid of profile. Related XML file restart system only to discover spring default read Jndi name is spring.profiles.default instead of spring.profiles.active .