【发布时间】:2015-11-23 22:15:38
【问题描述】:
我在我的 applicationContext 中配置了一个休眠的 SessionFactoryBean,它已经有一个真实的数据源作为属性。但是我想通过覆盖已经注入 sessionfactory 的实际数据源,在我的测试类中使用另一个本地/模拟数据源。
主应用Context中的bean定义是这样的。
<bean id="SessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"
abstract="false" scope="singleton" lazy-init="default" autowire="default">
<property name="dataSource" ref="pcfDataSource"/>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">$`db.hibernate.dialect} </prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.current_session_context_class">thread</prop>
<prop key="hibernate.cache.use_second_level_cache">true</prop>
<prop key="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory</prop>
</props>
</property>
</bean>
我的测试用例中有一个像这样的本地数据源:
template = InitializeDataSource.getInitializedDataSource();
DataSource dataSource = template.getDataSource;
我需要用底部的数据源覆盖注入的数据源
【问题讨论】:
-
你可以看看使用java配置文件。
标签: java spring hibernate unit-testing sessionfactory