Spring MVC 3 Hibernate 4 Multi databases configuration -
i have manage multiples databases in application configuration file app
<?xml version="1.0" encoding="utf-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context" xsi:schemalocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd"> <!-- scans classpath of application @components deploy beans --> <context:component-scan base-package="fr.tessa.jee.webmanager" /> <!-- configures @controller programming model --> <mvc:annotation-driven /> <!-- misc --> <bean id="viewresolver" class="org.springframework.web.servlet.view.internalresourceviewresolver"> <property name="viewclass" value="org.springframework.web.servlet.view.jstlview" /> <property name="suffix" value=".jsp" /> </bean> <!-- configure multipart resolver --> <bean id="multipartresolver" class="org.springframework.web.multipart.commons.commonsmultipartresolver"> <!-- 1 of properties available; maximum file size in bytes --> <property name="maxuploadsize" value="1000000" /> </bean> <!-- configures hibernate - database config --> <import resource="dbconfig/db-config.xml" /> <import resource="dbconfig/validationdb-config.xml" /> </beans>
and "db-config.xml" is
<?xml version="1.0" encoding="utf-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemalocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd"> <!-- hibernate info source --> <bean id="teodatasource" class="org.springframework.jdbc.datasource.drivermanagerdatasource"> <property name="driverclassname"><value>com.mysql.jdbc.driver</value></property> <property name="url"><value>jdbc:mysql://127.0.0.1/teodijon</value></property> <property name="username"><value>root</value></property> <property name="password"><value</value></property> </bean> <!-- hibernate session mill --> <bean id="teosessionfactory" class="org.springframework.orm.hibernate4.localsessionfactorybean"> <property name="datasource"><ref local="teodatasource"/></property> <property name="packagestoscan" value="fr.tessa.jee.webmanager.model" /> <property name="hibernateproperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.mysqldialect</prop> <prop key="hibernate.show_sql">true</prop> <prop key="hibernate.hbm2ddl.auto">update</prop> </props> </property> </bean> <!-- transaction manager single hibernate sessionfactory (alternative jta) hibernatetransactionmanager --> <tx:annotation-driven transaction-manager="teotransactionmanager"/> <bean id="teotransactionmanager" class="org.springframework.orm.hibernate4.hibernatetransactionmanager"> <property name="sessionfactory"><ref local="teosessionfactory"/></property> </bean> </beans>
and "validationdb-config.xml"
<?xml version="1.0" encoding="utf-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemalocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd"> <!-- hibernate info source --> <bean id="validationdatasource" class="org.springframework.jdbc.datasource.drivermanagerdatasource"> <property name="driverclassname"><value>com.mysql.jdbc.driver</value></property> <property name="url"><value>jdbc:mysql://127.0.0.1/validationdb</value></property> <property name="username"><value>root</value></property> <property name="password"><value></value></property> </bean> <!-- hibernate session mill --> <bean id="validationsessionfactory" class="org.springframework.orm.hibernate4.localsessionfactorybean"> <property name="datasource"><ref local="validationdatasource"/></property> <property name="packagestoscan" value="fr.tessa.jee.webmanager.validation.model" /> <property name="hibernateproperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.mysqldialect</prop> <prop key="hibernate.show_sql">true</prop> <prop key="hibernate.hbm2ddl.auto">update</prop> </props> </property> </bean> <!-- transaction manager single hibernate sessionfactory (alternative jta) hibernatetransactionmanager --> <tx:annotation-driven transaction-manager="validationtransactionmanager"/> <bean id="validationtransactionmanager" class="org.springframework.orm.hibernate4.hibernatetransactionmanager"> <property name="sessionfactory"><ref local="validationsessionfactory"/></property> </bean> </beans>
i have user class in bundle fr.tessa.jee.webmanager.validation.model , client in bundle fr.tessa.jee.webmanager.model; probleme when seek user list have error no session found current thread client list it's fine , when start importing "validationdb-config.xml" in app-config
<import resource="dbconfig/validationdb-config.xml" /> <import resource="dbconfig/db-config.xml" />
the error arrive when seek clients list
what probleme configuration? help please :(
i find probleme, probleme in transactional methode within service have specify id of transaction-manager this
@transactional(readonly = true, value="teotransactionmanager") public list<client> getclientlist() { homecoming clientdao.getclients(); }
while me in begin puted @transactional(readonly = true)
hibernate spring-mvc connection multiple-databases
No comments:
Post a Comment