I would like my applicationcontext to load a different file if I am running my unit tests, versus if I am deploying to a container.
I would like to use the in memory Hsqldb for quickly running through my tests that hit the database. For actual deployment, I want to use a mysql db.
Here is what I have so far:
However, this is using the WEB-INF/jdbc.properties file. Right now I will need to go in and manually comment out the mysql db properties and uncomment the hsqldb properties and keep going back and forth with the same process.Code:<!-- ======================== Persistence Layer ============================ --> <!-- Configurer that replaces ${...} placeholders with values from a properties file --> <!-- (in this case, JDBC-related settings for the dataSource definition below) --> <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="location" value="/WEB-INF/jdbc.properties"/> </bean> <!-- Simple local DataSource that works in any environment. This uses the JDBC DriverManager to obtain connections, and does NOT perform connection pooling. Connection pooling is essential to all real-world applications. This definition is good for getting started, as it introduces no dependencies beyond the JDK, but DriverManagerDataSource is not intended for production usage. --> <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName" value="${jdbc.driverClassName}"/> <property name="url" value="${jdbc.url}"/> <property name="username" value="${jdbc.username}"/> <property name="password" value="${jdbc.password}"/> </bean> <bean id="baseDao" class="com.infoglide.biscuit.dao.BaseDaoImpl" abstract="true"> <constructor-arg> <ref bean="dataSource"/> </constructor-arg> <constructor-arg> <ref bean="biscuitManager"/> </constructor-arg> </bean>
In the style of dependency injection, how do I make this such that when running my tests, I "inject" in a new hsqljdbc.properties with my test db config and all other times I use the jdbc.properties? The manual commenting/uncommenting seems very crude.


Reply With Quote