Commit 21ada2dd by fengshuonan

完善多数据源的测试接口

parent f289ec29
...@@ -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 {
......
/**
* 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();
}
}
package cn.stylefeng.guns.multi; package cn.stylefeng.guns.modular.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;
......
package cn.stylefeng.guns.multi; package cn.stylefeng.guns.modular.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;
......
package cn.stylefeng.guns.multi; package cn.stylefeng.guns.modular.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;
@Test @Transactional(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;
} }
......
...@@ -41,7 +41,7 @@ spring: ...@@ -41,7 +41,7 @@ spring:
# 多数据源情况的配置 # 多数据源情况的配置
guns: guns:
muti-datasource: muti-datasource:
open: false open: true
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
......
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