Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
I
impnhyw
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wangjinjing
impnhyw
Commits
235ac39b
Commit
235ac39b
authored
Oct 26, 2020
by
wangjinjing
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
双数据源
parent
48569dbe
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
129 additions
and
15 deletions
+129
-15
WebRoot/WEB-INF/springBase.xml
WebRoot/WEB-INF/springBase.xml
+113
-10
config/db.properties
config/db.properties
+16
-5
No files found.
WebRoot/WEB-INF/springBase.xml
View file @
235ac39b
...
@@ -23,6 +23,8 @@
...
@@ -23,6 +23,8 @@
<context:component-scan
base-package=
"cn.map.*"
/>
<context:component-scan
base-package=
"cn.map.*"
/>
<context:component-scan
base-package=
"cn.yw.*"
/>
<context:component-scan
base-package=
"cn.yw.*"
/>
<context:component-scan
base-package=
"cn.nhyw.*"
/>
<context:component-scan
base-package=
"cn.nhyw.*"
/>
<context:component-scan
base-package=
"cn.socket"
/>
<!--
<!--
<bean id="placeholderConfig" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<bean id="placeholderConfig" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location">
<property name="location">
...
@@ -42,7 +44,11 @@
...
@@ -42,7 +44,11 @@
</bean>
</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}"
/>
<property
name=
"driverClassName"
value=
"${datasource1.driver}"
/>
...
@@ -57,20 +63,68 @@
...
@@ -57,20 +63,68 @@
<property
name=
"minIdle"
value=
"${jdbc.minIdle}"
/>
<property
name=
"minIdle"
value=
"${jdbc.minIdle}"
/>
<property
name=
"maxIdle"
value=
"${jdbc.maxIdle}"
/>
<property
name=
"maxIdle"
value=
"${jdbc.maxIdle}"
/>
<property
name=
"maxTotal"
value=
"${jdbc.maxTotal}"
/>
<property
name=
"removeAbandonedOnBorrow"
value=
"${jdbc.removeAbandonedOnBorrow}"
/>
<property
name=
"defaultAutoCommit"
value=
"${jdbc.defaultAutoCommit}"
/>
<property
name=
"logAbandoned"
value=
"${jdbc.logAbandoned}"
/>
<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=
"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>
<bean
id=
"sqlMapClient"
class=
"org.springframework.orm.ibatis.SqlMapClientFactoryBean"
>
<bean
id=
"sqlMapClient"
class=
"org.springframework.orm.ibatis.SqlMapClientFactoryBean"
>
<property
name=
"configLocation"
>
<property
name=
"configLocation"
>
<value>
classpath:sqlMapConfig.xml
</value>
<value>
classpath:sqlMapConfig.xml
</value>
</property>
</property>
<property
name=
"dataSource"
>
<property
name=
"dataSource"
>
<ref
bean=
"dataSource"
/>
<ref
bean=
"d
ynamicD
ataSource"
/>
</property>
</property>
<!-- <property name="lobHandler"><ref local="oracleLobHandler"/></property> -->
<!-- <property name="lobHandler"><ref local="oracleLobHandler"/></property> -->
</bean>
</bean>
...
@@ -79,7 +133,7 @@
...
@@ -79,7 +133,7 @@
<bean
id=
"transactionManager"
class=
"org.springframework.jdbc.datasource.DataSourceTransactionManager"
>
<bean
id=
"transactionManager"
class=
"org.springframework.jdbc.datasource.DataSourceTransactionManager"
>
<property
name=
"dataSource"
>
<property
name=
"dataSource"
>
<ref
local=
"dataSource"
/>
<ref
local=
"d
ynamicD
ataSource"
/>
</property>
</property>
</bean>
</bean>
...
@@ -91,14 +145,22 @@
...
@@ -91,14 +145,22 @@
</tx:attributes>
</tx:attributes>
</tx:advice>
</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:config>
<aop:pointcut
id=
"netmanagerServiceOperation"
expression=
"bean(*Service)"
/>
<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:config>
<aop:aspectj-autoproxy
proxy-target-class=
"true"
/>
<aop:config>
<aop:config>
<aop:aspect
id=
"operateAspect"
ref=
"aspectService"
>
<aop:aspect
id=
"operateAspect"
ref=
"aspectService"
>
<aop:pointcut
expression=
"execution(* cn.im.*.action.*Action.*(..)) or execution(* cn.bsystem.*.action.*Action.*(..))"
id=
"logPointcut"
/>
<aop:pointcut
expression=
"execution(* cn.im.*.action.*Action.*(..)) or execution(* cn.bsystem.*.action.*Action.*(..))"
id=
"logPointcut"
/>
...
@@ -108,5 +170,46 @@
...
@@ -108,5 +170,46 @@
</aop:aspect>
</aop:aspect>
</aop:config>
</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"/>-->
<!--<!– 每天十点 –>-->
<!--<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"
/>
<import
resource=
"springService.xml"
/>
</beans>
</beans>
config/db.properties
View file @
235ac39b
...
@@ -19,13 +19,22 @@ datasource1.username=IMP
...
@@ -19,13 +19,22 @@ datasource1.username=IMP
datasource1.password
=
imp
datasource1.password
=
imp
#数据源2
#数据源2
datasource2.driver
=
com.mysql.jdbc.
Driver
datasource2.driver
=
oracle.jdbc.Oracle
Driver
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
#datasource2.driver=org.gjt.mm.mysql.Driver
#
#
...
@@ -51,4 +60,6 @@ jdbc.removeAbandonedTimeout=600
...
@@ -51,4 +60,6 @@ jdbc.removeAbandonedTimeout=600
jdbc.testWhileIdle
=
true
jdbc.testWhileIdle
=
true
jdbc.logAbandoned
=
true
jdbc.logAbandoned
=
true
\ No newline at end of file
jdbc.defaultAutoCommit
=
true
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment