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
21ada2dd
Commit
21ada2dd
authored
Mar 31, 2019
by
fengshuonan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
完善多数据源的测试接口
parent
f289ec29
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
59 additions
and
12 deletions
+59
-12
src/main/java/cn/stylefeng/guns/GunsApplication.java
+2
-1
src/main/java/cn/stylefeng/guns/modular/demos/controller/TestMultiController.java
+45
-0
src/main/java/cn/stylefeng/guns/modular/demos/service/GunsDbService.java
+1
-1
src/main/java/cn/stylefeng/guns/modular/demos/service/OtherDbService.java
+1
-1
src/main/java/cn/stylefeng/guns/modular/demos/service/TestMultiDbService.java
+9
-8
src/main/resources/application-local.yml
+1
-1
No files found.
src/main/java/cn/stylefeng/guns/GunsApplication.java
View file @
21ada2dd
...
@@ -15,6 +15,7 @@
...
@@ -15,6 +15,7 @@
*/
*/
package
cn
.
stylefeng
.
guns
;
package
cn
.
stylefeng
.
guns
;
import
cn.stylefeng.roses.core.config.MybatisDataSourceAutoConfiguration
;
import
cn.stylefeng.roses.core.config.WebAutoConfiguration
;
import
cn.stylefeng.roses.core.config.WebAutoConfiguration
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
...
@@ -28,7 +29,7 @@ import org.springframework.scheduling.annotation.EnableScheduling;
...
@@ -28,7 +29,7 @@ import org.springframework.scheduling.annotation.EnableScheduling;
* @author stylefeng
* @author stylefeng
* @Date 2017/5/21 12:06
* @Date 2017/5/21 12:06
*/
*/
@SpringBootApplication
(
exclude
=
{
WebAutoConfiguration
.
class
})
@SpringBootApplication
(
exclude
=
{
WebAutoConfiguration
.
class
,
MybatisDataSourceAutoConfiguration
.
class
})
@EnableScheduling
@EnableScheduling
public
class
GunsApplication
{
public
class
GunsApplication
{
...
...
src/main/java/cn/stylefeng/guns/modular/demos/controller/TestMultiController.java
0 → 100644
View file @
21ada2dd
/**
* Copyright 2018-2020 stylefeng & fengshuonan (https://gitee.com/stylefeng)
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
cn
.
stylefeng
.
guns
.
modular
.
demos
.
controller
;
import
cn.stylefeng.guns.modular.demos.service.TestMultiDbService
;
import
cn.stylefeng.roses.core.base.controller.BaseController
;
import
cn.stylefeng.roses.core.reqres.response.SuccessResponseData
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
/**
* 测试多数据源回滚
*
* @author stylefeng
* @Date 2018/7/20 23:39
*/
@RestController
@RequestMapping
(
"/multi"
)
public
class
TestMultiController
extends
BaseController
{
@Autowired
private
TestMultiDbService
testMultiDbService
;
@RequestMapping
(
""
)
public
Object
auth
()
{
testMultiDbService
.
beginTest
();
return
SuccessResponseData
.
success
();
}
}
src/
test/java/cn/stylefeng/guns/multi
/GunsDbService.java
→
src/
main/java/cn/stylefeng/guns/modular/demos/service
/GunsDbService.java
View file @
21ada2dd
package
cn
.
stylefeng
.
guns
.
m
ulti
;
package
cn
.
stylefeng
.
guns
.
m
odular
.
demos
.
service
;
import
cn.hutool.core.util.RandomUtil
;
import
cn.hutool.core.util.RandomUtil
;
import
cn.stylefeng.guns.modular.system.entity.User
;
import
cn.stylefeng.guns.modular.system.entity.User
;
...
...
src/
test/java/cn/stylefeng/guns/multi
/OtherDbService.java
→
src/
main/java/cn/stylefeng/guns/modular/demos/service
/OtherDbService.java
View file @
21ada2dd
package
cn
.
stylefeng
.
guns
.
m
ulti
;
package
cn
.
stylefeng
.
guns
.
m
odular
.
demos
.
service
;
import
cn.hutool.core.util.RandomUtil
;
import
cn.hutool.core.util.RandomUtil
;
import
cn.stylefeng.guns.modular.system.entity.User
;
import
cn.stylefeng.guns.modular.system.entity.User
;
...
...
src/
test/java/cn/stylefeng/guns/multi
/TestMultiDbService.java
→
src/
main/java/cn/stylefeng/guns/modular/demos/service
/TestMultiDbService.java
View file @
21ada2dd
package
cn
.
stylefeng
.
guns
.
m
ulti
;
package
cn
.
stylefeng
.
guns
.
m
odular
.
demos
.
service
;
import
cn.stylefeng.guns.base.BaseJunit
;
import
org.junit.Test
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
/**
/**
* <p>
* <p>
*
管理员表 服务实现类
*
测试多数据源回滚的例子
* </p>
* </p>
*
*
* @author stylefeng
* @author stylefeng
* @since 2018-12-07
* @since 2018-12-07
*/
*/
public
class
TestMultiDbService
extends
BaseJunit
{
@Service
public
class
TestMultiDbService
{
@Autowired
@Autowired
private
GunsDbService
gunsDbService
;
private
GunsDbService
gunsDbService
;
...
@@ -20,14 +21,14 @@ public class TestMultiDbService extends BaseJunit {
...
@@ -20,14 +21,14 @@ public class TestMultiDbService extends BaseJunit {
@Autowired
@Autowired
private
OtherDbService
otherDbService
;
private
OtherDbService
otherDbService
;
@T
est
@T
ransactional
(
rollbackFor
=
Exception
.
class
)
public
void
addddd
()
{
public
void
beginTest
()
{
gunsDbService
.
gunsdb
();
gunsDbService
.
gunsdb
();
otherDbService
.
otherdb
();
otherDbService
.
otherdb
();
int
i
=
1
/
0
;
//
int i = 1 / 0;
}
}
...
...
src/main/resources/application-local.yml
View file @
21ada2dd
...
@@ -41,7 +41,7 @@ spring:
...
@@ -41,7 +41,7 @@ spring:
# 多数据源情况的配置
# 多数据源情况的配置
guns
:
guns
:
muti-datasource
:
muti-datasource
:
open
:
fals
e
open
:
tru
e
driver-class-name
:
com.mysql.cj.jdbc.Driver
driver-class-name
:
com.mysql.cj.jdbc.Driver
url
:
jdbc:mysql://127.0.0.1:3306/guns_test_db?autoReconnect=true&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=CONVERT_TO_NULL&useSSL=false&serverTimezone=CTT
url
:
jdbc:mysql://127.0.0.1:3306/guns_test_db?autoReconnect=true&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=CONVERT_TO_NULL&useSSL=false&serverTimezone=CTT
username
:
root
username
:
root
...
...
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