Sunday, 15 July 2012

java - How to create a bean definition only if the bean was not loaded before? -



java - How to create a bean definition only if the bean was not loaded before? -

i'm using hibernate , mybatis dao layer, altogether spring 3. beans configurations through xml. integration between hibernate , mybatis doesn't have problem when declare these beans in same xml file. tried decouple them in different files , problem raised on integration tests, since cannot execute tests mybatis since lacks transactionmanager bean. when configuration in single file, no problem because have this:

class="lang-xml prettyprint-override"><bean id="transactionmanager" class="org.springframework.orm.hibernate3.hibernatetransactionmanager"> <!-- sessionfactory bean provided hibernate configuration. problem: when decoupling configuration, there's no transactionmanager bean , tests fail. --> <property name="sessionfactory" ref="sessionfactory" /> </bean>

after splitting configuration, solved problem in test environment redefining transactionmanager bean in mybatis config xml.

class="lang-xml prettyprint-override"><bean id="transactionmanager" class="org.springframework.jdbc.datasource.datasourcetransactionmanager" > <property name="datasource" ref="datasource" /> </bean>

but have unit test both hibernate , mybatis required. how can avoid creation of transactionmanager defined in mybatis configuration utilize transactionmanager defined in hibernate configuration?

i split transactionmanager bean definition 3rd file. load 2 files (hibernate + transactionmanager or ibatis + transactionmanager) or 3 files ( hibernate + ibatis + transactionmanager) needed. transactionmanager can declared in "common" spring file imported. approach i've used in past. i've seen posts on how override spring bean definitions, people recommend against it.

java spring spring-transactions

No comments:

Post a Comment