Commit 235ac39b authored by wangjinjing's avatar wangjinjing

双数据源

parent 48569dbe
......@@ -23,6 +23,8 @@
<context:component-scan base-package="cn.map.*" />
<context:component-scan base-package="cn.yw.*" />
<context:component-scan base-package="cn.nhyw.*" />
<context:component-scan base-package="cn.socket"/>
<!--
<bean id="placeholderConfig" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location">
......@@ -42,7 +44,11 @@
</bean>
<bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource" destroy-method="close">
<bean id="dataSourceAspect" class="cn.datasource.DynamicDataSourceAspect" />
<!-- 数据源1-->
<bean id="datasource1" class="org.apache.commons.dbcp2.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${datasource1.driver}"/>
......@@ -57,20 +63,68 @@
<property name="minIdle" value="${jdbc.minIdle}"/>
<property name="maxIdle" value="${jdbc.maxIdle}"/>
<property name="maxTotal" value="${jdbc.maxTotal}"/>
<property name="removeAbandonedOnBorrow" value="${jdbc.removeAbandonedOnBorrow}"/>
<property name="logAbandoned" value="${jdbc.logAbandoned}"/>
<property name="defaultAutoCommit" value="${jdbc.defaultAutoCommit}"/>
<property name="removeAbandonedTimeout" value="${jdbc.removeAbandonedTimeout}"/>
<property name="testWhileIdle" value="${jdbc.testWhileIdle}"/>
</bean>
<!-- 数据源2-->
<bean id="datasource2" class="org.apache.commons.dbcp2.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${datasource2.driver}"/>
<property name="url" value="${datasource2.url}"/>
<property name="username" value="${datasource2.username}"/>
<property name="password" value="${datasource2.password}"/>
<property name="initialSize" value="${jdbc.initialSize}"/>
<property name="minIdle" value="${jdbc.minIdle}"/>
<property name="maxIdle" value="${jdbc.maxIdle}"/>
<property name="defaultAutoCommit" value="${jdbc.defaultAutoCommit}"/>
<property name="removeAbandonedTimeout" value="${jdbc.removeAbandonedTimeout}"/>
<property name="testWhileIdle" value="${jdbc.testWhileIdle}"/>
</bean>
<!-- 配置动态配置数据源 -->
<bean id ="dynamicDataSource" class= "cn.datasource.DynamicDataSource">
<!-- 默认使用dataSource1的数据源 -->
<property name ="defaultTargetDataSource" ref="datasource1"></property>
<property name ="targetDataSources">
<map key-type ="java.lang.String">
<entry key= "datasource1" value-ref="datasource1"></entry>
<entry key= "datasource2" value-ref="datasource2"></entry>
</map>
</property>
</bean>
<bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="configLocation">
<value>classpath:sqlMapConfig.xml</value>
</property>
<property name="dataSource">
<ref bean="dataSource" />
<ref bean="dynamicDataSource" />
</property>
<!-- <property name="lobHandler"><ref local="oracleLobHandler"/></property> -->
</bean>
......@@ -79,7 +133,7 @@
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource">
<ref local="dataSource" />
<ref local="dynamicDataSource" />
</property>
</bean>
......@@ -91,14 +145,22 @@
</tx:attributes>
</tx:advice>
<aop:aspectj-autoproxy proxy-target-class="true"/>
<aop:config>
<!-- 动态数据源切割 -->
<aop:aspect id="dynamicAspect" ref="dataSourceAspect" >
<aop:pointcut id="pointCut" expression="execution(* cn.*.service.*.*(..))" />
<aop:after pointcut-ref="pointCut" method="afterSwitchDS"/>
<aop:before pointcut-ref="pointCut" method="beforeSwitchDS"/>
</aop:aspect>
</aop:config>
<aop:config>
<aop:pointcut id="netmanagerServiceOperation" expression="bean(*Service)" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="netmanagerServiceOperation" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="netmanagerServiceOperation" />
</aop:config>
<aop:aspectj-autoproxy proxy-target-class="true"/>
<aop:config>
<aop:aspect id="operateAspect" ref="aspectService">
<aop:pointcut expression="execution(* cn.im.*.action.*Action.*(..)) or execution(* cn.bsystem.*.action.*Action.*(..))" id="logPointcut"/>
......@@ -108,5 +170,46 @@
</aop:aspect>
</aop:config>
<!-- 配置quartz,要执行的任务类 -->
<bean id="repaireInfoJob" class="cn.socket.quartz.repaireInfoJob"></bean>
<!-- 将需要执行的定时任务注入job中 -->
<bean id="jobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject" ref="repaireInfoJob"/>
<!-- 任务类中需要执行的方法 -->
<property name="targetMethod" value="doSomething"></property>
<!-- 上一次未执行完成的,要等待有再执行。 -->
<property name="concurrent" value="false"/>
</bean>
<!-- 基本的定时器,会绑定具体的任务。 -->
<bean id="trigger" class="org.springframework.scheduling.quartz.SimpleTriggerFactoryBean">
<property name="jobDetail" ref="jobDetail"/>
<property name="startDelay" value="3000"/>
<property name="repeatInterval" value="6000"/>
</bean>
<!-- 定时器,会绑定具体的任务。 -->
<!--<bean id="trigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">-->
<!--<property name="jobDetail" ref="jobDetail"/>-->
<!--&lt;!&ndash; 每天十点 &ndash;&gt;-->
<!--<property name="cronExpression" value="0 0 10 * * ?"></property>-->
<!--</bean>-->
<bean id="scheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="trigger"/>
</list>
</property>
</bean>
<import resource="springService.xml" />
</beans>
......@@ -19,13 +19,22 @@ datasource1.username=IMP
datasource1.password=imp
#数据源2
datasource2.driver=com.mysql.jdbc.Driver
datasource2.driver=oracle.jdbc.OracleDriver
datasource2.url=jdbc:mysql://127.0.0.1:3306/test
datasource2.url=jdbc:oracle:thin:@61.155.110.210:7001:orcl
datasource2.username=root
datasource2.username=IMP
datasource2.password=1qaz2wsx
datasource2.password=imp
#数据源2
#datasource2.driver=com.mysql.jdbc.Driver
#datasource2.url=jdbc:mysql://127.0.0.1:3306/test
#datasource2.username=root
#datasource2.password=1qaz2wsx
#
#datasource2.driver=org.gjt.mm.mysql.Driver
#
......@@ -51,4 +60,6 @@ jdbc.removeAbandonedTimeout=600
jdbc.testWhileIdle=true
jdbc.logAbandoned=true
\ No newline at end of file
jdbc.logAbandoned=true
jdbc.defaultAutoCommit=true
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment