Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
guns-vip
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
chenjunxiong
guns-vip
Commits
48d14e82
Commit
48d14e82
authored
Jun 25, 2017
by
naan1993
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
更新多数据源配置,增加一个开关控制是否开启多数据源
parent
ff877842
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
23 additions
and
9 deletions
+23
-9
src/main/java/com/stylefeng/guns/config/MybatisPlusConfig.java
+18
-7
src/main/java/com/stylefeng/guns/core/aop/MultiSourceExAop.java
+2
-0
src/main/resources/application.yml
+1
-0
src/test/java/com/stylefeng/guns/biz/BizTest.java
+2
-2
No files found.
src/main/java/com/stylefeng/guns/config/MybatisPlusConfig.java
View file @
48d14e82
...
@@ -9,6 +9,7 @@ import com.stylefeng.guns.config.properties.MutiDataSourceProperties;
...
@@ -9,6 +9,7 @@ import com.stylefeng.guns.config.properties.MutiDataSourceProperties;
import
com.stylefeng.guns.core.mutidatesource.DynamicDataSource
;
import
com.stylefeng.guns.core.mutidatesource.DynamicDataSource
;
import
org.mybatis.spring.annotation.MapperScan
;
import
org.mybatis.spring.annotation.MapperScan
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.transaction.annotation.EnableTransactionManagement
;
import
org.springframework.transaction.annotation.EnableTransactionManagement
;
...
@@ -33,31 +34,41 @@ public class MybatisPlusConfig {
...
@@ -33,31 +34,41 @@ public class MybatisPlusConfig {
@Autowired
@Autowired
MutiDataSourceProperties
mutiDataSourceProperties
;
MutiDataSourceProperties
mutiDataSourceProperties
;
/**
/**
*
druid数据库连接池
*
另一个数据源
*/
*/
private
DruidDataSource
dataSourceGuns
()
{
private
DruidDataSource
bizDataSource
()
{
DruidDataSource
dataSource
=
new
DruidDataSource
();
DruidDataSource
dataSource
=
new
DruidDataSource
();
druidProperties
.
config
(
dataSource
);
druidProperties
.
config
(
dataSource
);
mutiDataSourceProperties
.
config
(
dataSource
);
return
dataSource
;
return
dataSource
;
}
}
/**
/**
*
多数据源配置
*
guns的数据源
*/
*/
private
DruidDataSource
bizDataSource
()
{
private
DruidDataSource
dataSourceGuns
()
{
DruidDataSource
dataSource
=
new
DruidDataSource
();
DruidDataSource
dataSource
=
new
DruidDataSource
();
druidProperties
.
config
(
dataSource
);
druidProperties
.
config
(
dataSource
);
mutiDataSourceProperties
.
config
(
dataSource
);
return
dataSource
;
return
dataSource
;
}
}
/**
* 单数据源连接池配置
*/
@Bean
@ConditionalOnProperty
(
prefix
=
"guns"
,
name
=
"muti-datasource-open"
,
havingValue
=
"false"
)
public
DruidDataSource
singleDatasource
()
{
return
dataSourceGuns
();
}
/**
/**
*
动态数据源
*
多数据源连接池配置
*/
*/
@Bean
@Bean
public
DynamicDataSource
dataSource
()
{
@ConditionalOnProperty
(
prefix
=
"guns"
,
name
=
"muti-datasource-open"
,
havingValue
=
"true"
)
public
DynamicDataSource
mutiDataSource
()
{
DruidDataSource
dataSourceGuns
=
dataSourceGuns
();
DruidDataSource
dataSourceGuns
=
dataSourceGuns
();
DruidDataSource
bizDataSource
=
bizDataSource
();
DruidDataSource
bizDataSource
=
bizDataSource
();
...
...
src/main/java/com/stylefeng/guns/core/aop/MultiSourceExAop.java
View file @
48d14e82
...
@@ -10,6 +10,7 @@ import org.aspectj.lang.annotation.Around;
...
@@ -10,6 +10,7 @@ import org.aspectj.lang.annotation.Around;
import
org.aspectj.lang.annotation.Aspect
;
import
org.aspectj.lang.annotation.Aspect
;
import
org.aspectj.lang.annotation.Pointcut
;
import
org.aspectj.lang.annotation.Pointcut
;
import
org.aspectj.lang.reflect.MethodSignature
;
import
org.aspectj.lang.reflect.MethodSignature
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
;
import
org.springframework.core.Ordered
;
import
org.springframework.core.Ordered
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
...
@@ -24,6 +25,7 @@ import java.lang.reflect.Method;
...
@@ -24,6 +25,7 @@ import java.lang.reflect.Method;
*/
*/
@Aspect
@Aspect
@Component
@Component
@ConditionalOnProperty
(
prefix
=
"guns"
,
name
=
"muti-datasource-open"
,
havingValue
=
"true"
)
public
class
MultiSourceExAop
implements
Ordered
{
public
class
MultiSourceExAop
implements
Ordered
{
private
Logger
log
=
Logger
.
getLogger
(
this
.
getClass
());
private
Logger
log
=
Logger
.
getLogger
(
this
.
getClass
());
...
...
src/main/resources/application.yml
View file @
48d14e82
...
@@ -10,6 +10,7 @@ guns:
...
@@ -10,6 +10,7 @@ guns:
#file-upload-path: d:/tmp #文件上传目录(不配置的话为java.io.tmpdir目录)
#file-upload-path: d:/tmp #文件上传目录(不配置的话为java.io.tmpdir目录)
session-invalidate-time
:
1800
#session失效时间 单位:秒
session-invalidate-time
:
1800
#session失效时间 单位:秒
session-validation-interval
:
900
#多久检测一次失效的session 单位:秒
session-validation-interval
:
900
#多久检测一次失效的session 单位:秒
muti-datasource-open
:
false
#是否开启多数据源(true/false)
################### 项目启动端口 ###################
################### 项目启动端口 ###################
server
:
server
:
...
...
src/test/java/com/stylefeng/guns/biz/BizTest.java
View file @
48d14e82
...
@@ -20,8 +20,8 @@ public class BizTest extends BaseJunit {
...
@@ -20,8 +20,8 @@ public class BizTest extends BaseJunit {
public
void
test
()
{
public
void
test
()
{
//testService.testGuns();
//testService.testGuns();
//
testService.testBiz();
testService
.
testBiz
();
testService
.
testAll
();
//
testService.testAll();
}
}
}
}
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