SSH项目连接两个数据库
maven管理的SSH项目,要连接两个数据库,里面有相同的表名和entity名,xml和注解怎么配置,求解
ssh
数据库
maven
xml
------解决方案--------------------
<!-- 数据源 -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="${driver}"></property>
<property name="url" value="${url}"></property>
<property name="username" value="${user}"></property>
<property name="password" value="${pwd}"></property>
<property name="maxActive" value="40" />
<property name="initialSize" value="5" />
<property name="maxWait" value="60000" />
<property name="maxIdle" value="15" />
<property name="minIdle" value="5" />
</bean>
<!-- 数据源2 -->
<bean id="dataSourceForOld" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="${driverForOld}"></property>
<property name="url" value="${urlForOld}"></property>
<property name="username" value="${userForOld}"></property>
<property name="password" value="${pwdForOld}"></property>
<property name="maxActive" value="40" />
<property name="initialSize" value="5" />
<property name="maxWait" value="60000" />
<property name="maxIdle" value="15" />
<property name="minIdle" value="5" />
</bean>
<!-- SqlSessionFactory -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<property name="configLocation" value="classpath:mybatis_conf.xml"></property>
</bean>
<!-- SqlSessionFactory2 -->
<bean id="sqlSessionFactoryForOld" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSourceForOld"></property>
<property name="configLocation" value="classpath:mybatis_conf_old.xml"></property>
</bean>
<!-- 接口映射 -->
<bean id="mapper" class="org.mybatis.spring.mapper.MapperFactoryBean">
<property name="sqlSessionFactory" ref="sqlSessionFactory"></property>
<property name="mapperInterface" value="com.szmsd.msdTrack.mapper.Mapper"></property>
</bean>
<!-- 接口映射2 -->
<bean id="mapperForOld" class="org.mybatis.spring.mapper.MapperFactoryBean">
<property name="sqlSessionFactory" ref="sqlSessionFactoryForOld"></property>
<property name="mapperInterface" value="com.szmsd.msdTrack.mapper.MapperForOld"></property>
</bean>
<import resource="applicationContext_service.xml"/>
<import resource="applicationContext_action.xml"/>
我这是ssm 的 配置类是供你参考!
------解决方案--------------------这个我也刚学过,给你个链接看看把:
http://kindazrael.iteye.com/blog/982531
------解决方案--------------------