首先注意本框架是SSM,配置主要在两个地方。第一个是applicationContext.xml,第二个文件是Tomcat下面的context.xml里面
1.context.xml文件配置的代码如下:
注意标红的为不同点
数据源1路径配置:
<Resource name="CRM_DB" auth="Container" type="javax.sql.DataSource" maxActive="100" maxIdle="30" maxWait="10000" driverClassName="com.ibm.db2.jcc.DB2Driver"
username="root" password="123456" url="jdbc:db2://10.20.22.33:60000/crmdb">
</Resource>
数据源2路径配置:
<Resource name="STAGE_DB" auth="Container" type="javax.sql.DataSource" maxActive="100" maxIdle="30" maxWait="10000" driverClassName="com.ibm.db2.jcc.DB2Driver"
username="root" password="123456" url="jdbc:db2://10.20.22.33:60000/stagedb">
</Resource>
2.applicationContext.xml文件配置代码如下:
<bean id="crmDbDataSource" class="org.springframework.jndi.JndiObjectFactoryBean" >
<property name="jndiName"> <value>CRM_DB</value> </property>
</bean>
<bean id="stageDbDataSource" class="org.springframework.jndi.JndiObjectFactoryBean" >
<property name="jndiName"> <value>STAGE_DB</value> </property>
</bean>
<bean id="dynamicDataSource" class="com.huateng.ebank.framework.datasource.DynamicDataSource">
<property name="defaultTargetDataSource" ref="crmDbDataSource"></property>
<property name="targetDataSources">
<map>
<entry key="crmDbDataSource" value-ref="crmDbDataSource"></entry>
<entry key="stageDbDataSource" value-ref="stageDbDataSource"></entry>
</map>
</property>
</bean>
注意上面的代码为纯手工代码,不是复制粘贴,可能有些单词会拼错,请在使用时注意!!!