I have a Spring project that uses Maven and has several profiles to allow it to run on different setups with resource filtering. Some of the setups have JNDI and some do not. For the ones that do not a JDBC data source is required.
What is the best way to handle this given my setup? I want to avoid doing anything with multiple files and ant-run or anything like that. Which leaves me with:
- Setting up two beans and filtering my resources to include one or the other.
- Something I haven’t thought of?
Here’s an example of the first bullet:
<bean id="jdbcDataSource"
class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close"
p:driverClassName="${jdbc.driver}"
p:url="${jdbc.url}"
p:username="${jdbc.username}"
p:password="${jdbc.password}"/>
<bean id="jndiDataSource" class="org.springframework.jndi.JndiObjectFactoryBean"
p:jndiName="${jndi.name}" />
<bean id="someBean" class="com.whatever.SomeBeanImpl"
p:dataSource-ref="${dataSource}"/>
I’m interested to hear of other ways people have accomplished this and why they went with that solution. Or if they went with this solution and why.
Spring 3.1 provides profile support natively. In spring world it is known as Environment. Look here for more details.