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
8055e953
Commit
8055e953
authored
Jul 10, 2018
by
fengshuonan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修复多数据源不能使用的bug
parent
0ae277b9
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
235 additions
and
8 deletions
+235
-8
guns-admin/src/main/java/com/stylefeng/guns/config/datasource/MultiDataSourceConfig.java
+1
-1
guns-admin/src/main/java/com/stylefeng/guns/config/datasource/SingleDataSourceConfig.java
+1
-1
guns-admin/src/main/resources/application.yml
+3
-3
guns-admin/src/test/java/com/stylefeng/guns/multi/entity/Test.java
+49
-0
guns-admin/src/test/java/com/stylefeng/guns/multi/mapper/TestMapper.java
+16
-0
guns-admin/src/test/java/com/stylefeng/guns/multi/mapper/mapping/TestMapper.xml
+19
-0
guns-admin/src/test/java/com/stylefeng/guns/multi/service/TestService.java
+37
-0
guns-admin/src/test/java/com/stylefeng/guns/multi/service/impl/TestServiceImpl.java
+52
-0
guns-admin/src/test/java/com/stylefeng/guns/multi/test/BizTest.java
+27
-0
guns-admin/src/test/sql/test.sql
+30
-0
guns-core/src/main/resources/META-INF/spring.factories
+0
-3
No files found.
guns-
core/src/main/java/com/stylefeng/guns/core/config
/MultiDataSourceConfig.java
→
guns-
admin/src/main/java/com/stylefeng/guns/config/datasource
/MultiDataSourceConfig.java
View file @
8055e953
package
com
.
stylefeng
.
guns
.
co
re
.
config
;
package
com
.
stylefeng
.
guns
.
co
nfig
.
datasource
;
import
com.alibaba.druid.pool.DruidDataSource
;
import
com.alibaba.druid.pool.DruidDataSource
;
import
com.baomidou.mybatisplus.plugins.OptimisticLockerInterceptor
;
import
com.baomidou.mybatisplus.plugins.OptimisticLockerInterceptor
;
...
...
guns-
core/src/main/java/com/stylefeng/guns/core/config
/SingleDataSourceConfig.java
→
guns-
admin/src/main/java/com/stylefeng/guns/config/datasource
/SingleDataSourceConfig.java
View file @
8055e953
package
com
.
stylefeng
.
guns
.
co
re
.
config
;
package
com
.
stylefeng
.
guns
.
co
nfig
.
datasource
;
import
com.alibaba.druid.pool.DruidDataSource
;
import
com.alibaba.druid.pool.DruidDataSource
;
import
com.baomidou.mybatisplus.plugins.OptimisticLockerInterceptor
;
import
com.baomidou.mybatisplus.plugins.OptimisticLockerInterceptor
;
...
...
guns-admin/src/main/resources/application.yml
View file @
8055e953
...
@@ -30,7 +30,7 @@ mybatis-plus:
...
@@ -30,7 +30,7 @@ mybatis-plus:
typeAliasesPackage
:
com.stylefeng.guns.modular.system.model
typeAliasesPackage
:
com.stylefeng.guns.modular.system.model
log
:
log
:
path
:
/opt/guns/
logs
path
:
guns-
logs
---
---
...
@@ -57,8 +57,8 @@ spring:
...
@@ -57,8 +57,8 @@ spring:
#多数据源情况的配置
#多数据源情况的配置
guns
:
guns
:
muti-datasource
:
muti-datasource
:
open
:
fals
e
open
:
tru
e
url
:
jdbc:mysql://127.0.0.1:3306/
guns
?autoReconnect=true&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=CONVERT_TO_NULL&useSSL=false&serverTimezone=UTC
url
:
jdbc:mysql://127.0.0.1:3306/
test
?autoReconnect=true&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=CONVERT_TO_NULL&useSSL=false&serverTimezone=UTC
username
:
root
username
:
root
password
:
root
password
:
root
dataSourceNames
:
dataSourceNames
:
...
...
guns-admin/src/test/java/com/stylefeng/guns/multi/entity/Test.java
0 → 100644
View file @
8055e953
package
com
.
stylefeng
.
guns
.
multi
.
entity
;
import
com.baomidou.mybatisplus.annotations.TableId
;
import
com.baomidou.mybatisplus.enums.IdType
;
import
java.io.Serializable
;
/**
* <p>
*
* </p>
*
* @author fengshuonan
* @since 2018-07-10
*/
public
class
Test
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
@TableId
(
value
=
"aaa"
,
type
=
IdType
.
AUTO
)
private
Integer
aaa
;
private
String
bbb
;
public
Integer
getAaa
()
{
return
aaa
;
}
public
void
setAaa
(
Integer
aaa
)
{
this
.
aaa
=
aaa
;
}
public
String
getBbb
()
{
return
bbb
;
}
public
void
setBbb
(
String
bbb
)
{
this
.
bbb
=
bbb
;
}
@Override
public
String
toString
()
{
return
"Test{"
+
"aaa="
+
aaa
+
", bbb="
+
bbb
+
"}"
;
}
}
guns-admin/src/test/java/com/stylefeng/guns/multi/mapper/TestMapper.java
0 → 100644
View file @
8055e953
package
com
.
stylefeng
.
guns
.
multi
.
mapper
;
import
com.baomidou.mybatisplus.mapper.BaseMapper
;
import
com.stylefeng.guns.multi.entity.Test
;
/**
* <p>
* Mapper 接口
* </p>
*
* @author fengshuonan
* @since 2018-07-10
*/
public
interface
TestMapper
extends
BaseMapper
<
Test
>
{
}
guns-admin/src/test/java/com/stylefeng/guns/multi/mapper/mapping/TestMapper.xml
0 → 100644
View file @
8055e953
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper
namespace=
"share.example.modular.mapper.TestMapper"
>
<!-- 开启二级缓存 -->
<cache
type=
"org.mybatis.caches.ehcache.LoggingEhcache"
/>
<!-- 通用查询映射结果 -->
<resultMap
id=
"BaseResultMap"
type=
"com.stylefeng.guns.multi.entity.Test"
>
<id
column=
"aaa"
property=
"aaa"
/>
<result
column=
"bbb"
property=
"bbb"
/>
</resultMap>
<!-- 通用查询结果列 -->
<sql
id=
"Base_Column_List"
>
aaa, bbb
</sql>
</mapper>
guns-admin/src/test/java/com/stylefeng/guns/multi/service/TestService.java
0 → 100644
View file @
8055e953
package
com
.
stylefeng
.
guns
.
multi
.
service
;
/**
* <p>
* 服务类
* </p>
*
* @author fengshuonan
* @since 2018-07-10
*/
public
interface
TestService
{
/**
* 测试多数据源的业务
*
* @author stylefeng
* @Date 2017/6/23 23:02
*/
void
testBiz
();
/**
* 测试多数据源的业务
*
* @author stylefeng
* @Date 2017/6/23 23:02
*/
void
testGuns
();
/**
* 测试多数据源的业务
*
* @author stylefeng
* @Date 2017/6/23 23:02
*/
void
testAll
();
}
guns-admin/src/test/java/com/stylefeng/guns/multi/service/impl/TestServiceImpl.java
0 → 100644
View file @
8055e953
package
com
.
stylefeng
.
guns
.
multi
.
service
.
impl
;
import
com.stylefeng.guns.core.common.constant.DatasourceEnum
;
import
com.stylefeng.guns.core.mutidatasource.annotion.DataSource
;
import
com.stylefeng.guns.multi.entity.Test
;
import
com.stylefeng.guns.multi.mapper.TestMapper
;
import
com.stylefeng.guns.multi.service.TestService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
/**
* <p>
* 服务实现类
* </p>
*
* @author fengshuonan
* @since 2018-07-10
*/
@Service
public
class
TestServiceImpl
implements
TestService
{
@Autowired
private
TestMapper
testMapper
;
@Override
@DataSource
(
name
=
DatasourceEnum
.
DATA_SOURCE_BIZ
)
@Transactional
public
void
testBiz
()
{
Test
test
=
new
Test
();
test
.
setBbb
(
"bizTest"
);
testMapper
.
insert
(
test
);
}
@Override
@DataSource
(
name
=
DatasourceEnum
.
DATA_SOURCE_GUNS
)
@Transactional
public
void
testGuns
()
{
Test
test
=
new
Test
();
test
.
setBbb
(
"gunsTest"
);
testMapper
.
insert
(
test
);
}
@Override
@Transactional
public
void
testAll
()
{
testBiz
();
testGuns
();
//int i = 1 / 0;
}
}
guns-admin/src/test/java/com/stylefeng/guns/multi/test/BizTest.java
0 → 100644
View file @
8055e953
package
com
.
stylefeng
.
guns
.
multi
.
test
;
import
com.stylefeng.guns.base.BaseJunit
;
import
com.stylefeng.guns.multi.service.TestService
;
import
org.junit.Test
;
import
org.springframework.beans.factory.annotation.Autowired
;
/**
* 业务测试
*
* @author fengshuonan
* @date 2017-06-23 23:12
*/
public
class
BizTest
extends
BaseJunit
{
@Autowired
TestService
testService
;
@Test
public
void
test
()
{
//testService.testGuns();
testService
.
testBiz
();
//testService.testAll();
}
}
guns-admin/src/test/sql/test.sql
0 → 100644
View file @
8055e953
/*
Navicat Premium Data Transfer
Source Server : localhost
Source Server Type : MySQL
Source Server Version : 50719
Source Host : localhost:3306
Source Schema : guns
Target Server Type : MySQL
Target Server Version : 50719
File Encoding : 65001
Date: 10/07/2018 14:09:19
*/
SET
NAMES
utf8mb4
;
SET
FOREIGN_KEY_CHECKS
=
0
;
-- ----------------------------
-- Table structure for test
-- ----------------------------
DROP
TABLE
IF
EXISTS
`test`
;
CREATE
TABLE
`test`
(
`aaa`
int
(
11
)
NOT
NULL
AUTO_INCREMENT
,
`bbb`
varchar
(
255
)
DEFAULT
NULL
,
PRIMARY
KEY
(
`aaa`
)
USING
BTREE
)
ENGINE
=
InnoDB
AUTO_INCREMENT
=
12
DEFAULT
CHARSET
=
utf8
ROW_FORMAT
=
DYNAMIC
;
SET
FOREIGN_KEY_CHECKS
=
1
;
guns-core/src/main/resources/META-INF/spring.factories
View file @
8055e953
...
@@ -2,7 +2,5 @@
...
@@ -2,7 +2,5 @@
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.stylefeng.guns.core.base.controller.GlobalController,\
com.stylefeng.guns.core.base.controller.GlobalController,\
com.stylefeng.guns.core.config.DefaultFastjsonConfig,\
com.stylefeng.guns.core.config.DefaultFastjsonConfig,\
com.stylefeng.guns.core.config.MultiDataSourceConfig,\
com.stylefeng.guns.core.config.SingleDataSourceConfig,\
com.stylefeng.guns.core.config.DefaultProperties,\
com.stylefeng.guns.core.config.DefaultProperties,\
com.stylefeng.guns.core.config.DefaultWebConfig
com.stylefeng.guns.core.config.DefaultWebConfig
\ 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