Specifically I wanted to use an embedded database to allow fast, environment independent development, unit and integration testing vs using external database in production, qa and staging environments to which access is defined through jndi parameter.
Context file:
<context:property-placeholder location="classpath*:profile.properties"/> <!-- Local profile using embedded database--> <beans profile="local"> <jdbc:embedded-database id="dataSource"> <jdbc:script location="classpath:scripts/hsql_tables.sql"/> </jdbc:embedded-database> </beans> <!-- Remote profile using external data source --> <beans profile="remote"> <jee:jndi-lookup id="dataSource" jndiname="java:comp/env/jdbc/dataSource"/> </beans>Property file ( profile.properties ):
spring.profiles.active="remote"By default, system properties take precedence over environment variables thus spring.profiles.active parameter submitted through the JVM system property will be used instead of value in profile.properties file.
Alternative solution:
Another possible way of accomplishing same goal (without the use of spring bean profiles) would be to import a different context file for the database in different environments, but bean profiles seemed like a more appropriate solution in this case.
<import resource="${database.type}-context.xml"/>