I have created a environment variable entry of profile to be active in my web application: In setenv.bat file in Tomcat server JAVA_OPTS=%JAVA_OPTS% -Dspring.profiles.active=prod
And when my application tries to load datasource using active profile it gives exception as no active profile is set.
Entry in applicationcontext.xml:
<beans profile="dev">
<bean id="myDataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"></property>
<property name="url" value="jdbc:oracle:thin:@localhost:1521:books"></property>
<property name="username" value="system"></property>
<property name="password" value="xyz"></property>
</bean>
</beans>
<beans profile="prod">
<bean id="myDataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"></property>
<property name="url" value="jdbc:oracle:thin:@localhost:1521:orcl"></property>
<property name="username" value="system"></property>
<property name="password" value="abc"></property>
</bean>
</beans>
</beans>
However when i do the same thing via web.xml entry it works:
<context-param>
<param-name>spring.profiles.active</param-name>
<param-value>dev</param-value>
</context-param>
Can anyone please tell me what is the problem in loading profile using environment variable.