背景:在springboot配置多数据源(一)的基础上进行
1. application.yml文件增加数据源
spring:
second-datasource:
username: root
password: 1234
jdbc-url: jdbc:mysql://127.0.0.1:3306/test2?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC
driver-class-name: com.mysql.cj.jdbc.Driver
type: com.zaxxer.hikari.HikariDataSource
hikari:
maximum-pool-size: 20
max-lifetime: 1800000
idle-timeout: 30000
data-source-properties:
prepStmtCacheSize: 250
prepStmtCacheSqlLimit: 2048
cachePrepStmts: true
useServerPrepStmts: true
third-datasource:
username: root
password: 1234
jdbc-url: jdbc:mysql://127.0.0.1:3306/test3?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC
driver-class-name: com.mysql.cj.jdbc.Driver
type: com.zaxxer.hikari.HikariDataSource
hikari:
maximum-pool-size: 20
max-lifetime: 1800000
idle-timeout: 30000
data-source-properties:
prepStmtCacheSize: 250
prepStmtCacheSqlLimit: 2048
cachePrepStmts: true
useServerPrepStmts: true
fourth-datasource:
username: root
password: 1234
jdbc-url: jdbc:mysql://127.0.0.1:3306/test4?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC
driver-class-name: com.mysql.cj.jdbc.Driver
type: com.zaxxer.hikari.HikariDataSource
hikari:
maximum-pool-size: 20
max-lifetime: 1800000
idle-timeout: 30000
data-source-properties:
prepStmtCacheSize: 250
prepStmtCacheSqlLimit: 2048
cachePrepStmts: true
useServerPrepStmts: true
2. 添加数据库配置(DataBaseConfig.java)
@Bean(name = "secondDataSource")
@ConfigurationProperties(prefix = "spring.second-datasource")
public DataSource secondDataSource() {
return DataSourceBuilder.create().build();
}
@Bean(name = "thirdDataSource")
@ConfigurationProperties(prefix = "spring.third-datasource")
public DataSource thirdDataSource() {
return DataSourceBuilder.create().build();
}
@Bean(name = "fourthDataSource")
@ConfigurationProperties(prefix = "spring.fourth-datasource")
public DataSource fourthDataSource() {
return DataSourceBuilder.create().build();
}
3. 分别进行各数据源配置
package com.zsx.config;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.SqlSessionTemplate;
import org.mybatis.spring.annotation.MapperScan;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import javax.sql.DataSource;
@Configuration
@MapperScan(basePackages = {"com.zsx.mapper.primary"}, sqlSessionFactoryRef = "primarySqlSessionFactory")
public class MybatisDBPrimaryConfig {
private static final Logger LOGGER = LoggerFactory.getLogger(MybatisDBPrimaryConfig.class);
@Bean(name = "primarySqlSessionFactory")
public SqlSessionFactory primarySqlSessionFactory(@Qualifier("primaryDataSource") DataSource primaryDataSource) throws Exception {
LOGGER.info("====================");
LOGGER.info("primaryDataSource=========" + primaryDataSource);
SqlSessionFactoryBean factoryBean = new SqlSessionFactoryBean();
factoryBean.setDataSource(primaryDataSource);
factoryBean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath:mybatis/mapper/primary/*.xml"));
return factoryBean.getObject();
}
@Bean(name = "primarySqlSessionTemplate")
public SqlSessionTemplate primarySqlSessionTemplate(@Qualifier("primarySqlSessionFactory") SqlSessionFactory sqlSessionFactory) {
return new SqlSessionTemplate(sqlSessionFactory);
}
@Bean(name = "primaryTransactionManager")
public DataSourceTransactionManager primaryTransactionManager(@Qualifier("primaryDataSource") DataSource primaryDataSource) {
return new DataSourceTransactionManager(primaryDataSource);
}
}
package com.zsx.config;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.SqlSessionTemplate;
import org.mybatis.spring.annotation.MapperScan;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import javax.sql.DataSource;
@Configuration
@MapperScan(basePackages = {"com.zsx.mapper.second"}, sqlSessionFactoryRef = "secondSqlSessionFactory")
public class MybatisDBSecondConfig {
private static final Logger LOGGER = LoggerFactory.getLogger(MybatisDBSecondConfig.class);
@Bean(name = "secondSqlSessionFactory")
public SqlSessionFactory secondSqlSessionFactory(@Qualifier("secondDataSource") DataSource secondDataSource) throws Exception {
LOGGER.info("====================");
LOGGER.info("secondDataSource=========" + secondDataSource);
SqlSessionFactoryBean factoryBean = new SqlSessionFactoryBean();
factoryBean.setDataSource(secondDataSource);
factoryBean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath:mybatis/mapper/second/*.xml"));
return factoryBean.getObject();
}
@Bean(name = "secondSqlSessionTemplate")
public SqlSessionTemplate secondSqlSessionTemplate(@Qualifier("secondSqlSessionFactory") SqlSessionFactory sqlSessionFactory) {
return new SqlSessionTemplate(sqlSessionFactory);
}
@Bean(name = "secondTransactionManager")
public DataSourceTransactionManager secondTransactionManager(@Qualifier("secondDataSource") DataSource secondDataSource) {
return new DataSourceTransactionManager(secondDataSource);
}
}
package com.zsx.config;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.SqlSessionTemplate;
import org.mybatis.spring.annotation.MapperScan;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import javax.sql.DataSource;
@Configuration
@MapperScan(basePackages = {"com.zsx.mapper.third"}, sqlSessionFactoryRef = "thirdSqlSessionFactory")
public class MybatisDBThirdConfig {
private static final Logger LOGGER = LoggerFactory.getLogger(MybatisDBThirdConfig.class);
@Bean(name = "thirdSqlSessionFactory")
public SqlSessionFactory sqlSessionFactory(@Qualifier("thirdDataSource") DataSource thirdDataSource) throws Exception {
LOGGER.info("====================");
LOGGER.info("thirdDataSource=========" + thirdDataSource);
SqlSessionFactoryBean factoryBean = new SqlSessionFactoryBean();
factoryBean.setDataSource(thirdDataSource);
factoryBean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath:mybatis/mapper/third/*.xml"));
return factoryBean.getObject();
}
@Bean(name = "thirdSqlSessionTemplate")
public SqlSessionTemplate thirdSqlSessionTemplate(@Qualifier("thirdSqlSessionFactory") SqlSessionFactory sqlSessionFactory) {
return new SqlSessionTemplate(sqlSessionFactory);
}
@Bean(name = "thirdTransactionManager")
public DataSourceTransactionManager thirdTransactionManager(@Qualifier("thirdDataSource") DataSource thirdDataSource) {
return new DataSourceTransactionManager(thirdDataSource);
}
}
4. 分别编写对应的数据接口
package com.zsx.mapper.primary;
import com.zsx.entity.User;
import org.springframework.stereotype.Repository;
@Repository("userMapper0")
public interface UserMapper {
User findById(Integer id);
User findById1(Integer id);
}
package com.zsx.mapper.second;
import com.zsx.entity.User;
import org.springframework.stereotype.Repository;
@Repository("userMapper2")
public interface UserMapper {
User findById(Integer id);
}
package com.zsx.mapper.third;
import com.zsx.entity.User;
import org.springframework.stereotype.Repository;
@Repository("userMapper3")
public interface UserMapper {
User findById(Integer id);
}
5. 分别在资源目录下创建键对应的mapper映射文件(resources\mybatis\mapper\primary\primary-user-mapper.xml、resources\mybatis\mapper\second\second-user-mapper.xml、resources\mybatis\mapper\third\third-user-mapper.xml)
5.1 primary-user-mapper.xml
5.2 second-user-mapper.xml
5.3 third-user-mapper.xml
6. 测试类
package com.zsx.test.mapper;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit.jupiter.SpringExtension;
@ExtendWith(SpringExtension.class)
@SpringBootTest
public class UserMapperTest {
@Autowired
@Qualifier("userMapper0")
private com.zsx.mapper.primary.UserMapper userMapper0;
@Autowired
@Qualifier("userMapper2")
private com.zsx.mapper.second.UserMapper userMapper2;
@Autowired
@Qualifier("userMapper3")
private com.zsx.mapper.third.UserMapper userMapper3;
@Test
void testFindById() {
System.out.println(userMapper0.findById(1));
System.out.println(userMapper2.findById(1));
System.out.println(userMapper3.findById(1));
}
}
7. 运行测试方法,查看测试结果
C:\software\jdk-11.0.3\bin\java.exe -ea -Didea.test.cyclic.buffer.size=1048576 "-javaagent:C:\software\JetBrains\IntelliJ IDEA 2019.1.3\lib\idea_rt.jar=18138:C:\software\JetBrains\IntelliJ IDEA 2019.1.3\bin" -Dfile.encoding=UTF-8 -classpath "C:\software\JetBrains\IntelliJ IDEA 2019.1.3\lib\idea_rt.jar;C:\software\JetBrains\IntelliJ IDEA 2019.1.3\plugins\junit\lib\junit-rt.jar;C:\software\JetBrains\IntelliJ IDEA 2019.1.3\plugins\junit\lib\junit5-rt.jar;D:\repository\org\junit\vintage\junit-vintage-engine\5.3.2\junit-vintage-engine-5.3.2.jar;D:\repository\org\apiguardian\apiguardian-api\1.0.0\apiguardian-api-1.0.0.jar;D:\repository\org\junit\platform\junit-platform-engine\1.3.2\junit-platform-engine-1.3.2.jar;D:\repository\org\junit\platform\junit-platform-commons\1.3.2\junit-platform-commons-1.3.2.jar;D:\repository\org\opentest4j\opentest4j\1.1.1\opentest4j-1.1.1.jar;D:\repository\junit\junit\4.12\junit-4.12.jar;D:\repository\org\hamcrest\hamcrest-core\1.3\hamcrest-core-1.3.jar;F:\IdeaProjects\event\target\test-classes;F:\IdeaProjects\event\target\classes;D:\repository\org\springframework\boot\spring-boot-starter-web\2.1.7.RELEASE\spring-boot-starter-web-2.1.7.RELEASE.jar;D:\repository\org\springframework\boot\spring-boot-starter\2.1.7.RELEASE\spring-boot-starter-2.1.7.RELEASE.jar;D:\repository\org\springframework\boot\spring-boot-starter-logging\2.1.7.RELEASE\spring-boot-starter-logging-2.1.7.RELEASE.jar;D:\repository\ch\qos\logback\logback-classic\1.2.3\logback-classic-1.2.3.jar;D:\repository\ch\qos\logback\logback-core\1.2.3\logback-core-1.2.3.jar;D:\repository\org\apache\logging\log4j\log4j-to-slf4j\2.11.2\log4j-to-slf4j-2.11.2.jar;D:\repository\org\apache\logging\log4j\log4j-api\2.11.2\log4j-api-2.11.2.jar;D:\repository\org\slf4j\jul-to-slf4j\1.7.26\jul-to-slf4j-1.7.26.jar;D:\repository\javax\annotation\javax.annotation-api\1.3.2\javax.annotation-api-1.3.2.jar;D:\repository\org\yaml\snakeyaml\1.23\snakeyaml-1.23.jar;D:\repository\org\springframework\boot\spring-boot-starter-json\2.1.7.RELEASE\spring-boot-starter-json-2.1.7.RELEASE.jar;D:\repository\com\fasterxml\jackson\core\jackson-databind\2.9.9\jackson-databind-2.9.9.jar;D:\repository\com\fasterxml\jackson\core\jackson-core\2.9.9\jackson-core-2.9.9.jar;D:\repository\com\fasterxml\jackson\datatype\jackson-datatype-jdk8\2.9.9\jackson-datatype-jdk8-2.9.9.jar;D:\repository\com\fasterxml\jackson\datatype\jackson-datatype-jsr310\2.9.9\jackson-datatype-jsr310-2.9.9.jar;D:\repository\com\fasterxml\jackson\module\jackson-module-parameter-names\2.9.9\jackson-module-parameter-names-2.9.9.jar;D:\repository\org\springframework\boot\spring-boot-starter-tomcat\2.1.7.RELEASE\spring-boot-starter-tomcat-2.1.7.RELEASE.jar;D:\repository\org\apache\tomcat\embed\tomcat-embed-core\9.0.22\tomcat-embed-core-9.0.22.jar;D:\repository\org\apache\tomcat\embed\tomcat-embed-el\9.0.22\tomcat-embed-el-9.0.22.jar;D:\repository\org\apache\tomcat\embed\tomcat-embed-websocket\9.0.22\tomcat-embed-websocket-9.0.22.jar;D:\repository\org\hibernate\validator\hibernate-validator\6.0.17.Final\hibernate-validator-6.0.17.Final.jar;D:\repository\javax\validation\validation-api\2.0.1.Final\validation-api-2.0.1.Final.jar;D:\repository\org\jboss\logging\jboss-logging\3.3.2.Final\jboss-logging-3.3.2.Final.jar;D:\repository\org\springframework\spring-web\5.1.9.RELEASE\spring-web-5.1.9.RELEASE.jar;D:\repository\org\springframework\spring-beans\5.1.9.RELEASE\spring-beans-5.1.9.RELEASE.jar;D:\repository\org\springframework\spring-webmvc\5.1.9.RELEASE\spring-webmvc-5.1.9.RELEASE.jar;D:\repository\org\springframework\spring-context\5.1.9.RELEASE\spring-context-5.1.9.RELEASE.jar;D:\repository\org\springframework\spring-expression\5.1.9.RELEASE\spring-expression-5.1.9.RELEASE.jar;D:\repository\org\springframework\boot\spring-boot-starter-aop\2.1.7.RELEASE\spring-boot-starter-aop-2.1.7.RELEASE.jar;D:\repository\org\springframework\spring-aop\5.1.9.RELEASE\spring-aop-5.1.9.RELEASE.jar;D:\repository\org\aspectj\aspectjweaver\1.9.4\aspectjweaver-1.9.4.jar;D:\repository\org\springframework\boot\spring-boot-starter-data-redis\2.1.7.RELEASE\spring-boot-starter-data-redis-2.1.7.RELEASE.jar;D:\repository\org\springframework\data\spring-data-redis\2.1.10.RELEASE\spring-data-redis-2.1.10.RELEASE.jar;D:\repository\org\springframework\data\spring-data-keyvalue\2.1.10.RELEASE\spring-data-keyvalue-2.1.10.RELEASE.jar;D:\repository\org\springframework\data\spring-data-commons\2.1.10.RELEASE\spring-data-commons-2.1.10.RELEASE.jar;D:\repository\org\springframework\spring-tx\5.1.9.RELEASE\spring-tx-5.1.9.RELEASE.jar;D:\repository\org\springframework\spring-oxm\5.1.9.RELEASE\spring-oxm-5.1.9.RELEASE.jar;D:\repository\org\springframework\spring-context-support\5.1.9.RELEASE\spring-context-support-5.1.9.RELEASE.jar;D:\repository\io\lettuce\lettuce-core\5.1.8.RELEASE\lettuce-core-5.1.8.RELEASE.jar;D:\repository\io\netty\netty-common\4.1.38.Final\netty-common-4.1.38.Final.jar;D:\repository\io\netty\netty-handler\4.1.38.Final\netty-handler-4.1.38.Final.jar;D:\repository\io\netty\netty-buffer\4.1.38.Final\netty-buffer-4.1.38.Final.jar;D:\repository\io\netty\netty-codec\4.1.38.Final\netty-codec-4.1.38.Final.jar;D:\repository\io\netty\netty-transport\4.1.38.Final\netty-transport-4.1.38.Final.jar;D:\repository\io\netty\netty-resolver\4.1.38.Final\netty-resolver-4.1.38.Final.jar;D:\repository\io\projectreactor\reactor-core\3.2.11.RELEASE\reactor-core-3.2.11.RELEASE.jar;D:\repository\org\reactivestreams\reactive-streams\1.0.2\reactive-streams-1.0.2.jar;D:\repository\org\mybatis\spring\boot\mybatis-spring-boot-starter\2.0.1\mybatis-spring-boot-starter-2.0.1.jar;D:\repository\org\mybatis\spring\boot\mybatis-spring-boot-autoconfigure\2.0.1\mybatis-spring-boot-autoconfigure-2.0.1.jar;D:\repository\org\mybatis\mybatis\3.5.1\mybatis-3.5.1.jar;D:\repository\org\mybatis\mybatis-spring\2.0.1\mybatis-spring-2.0.1.jar;D:\repository\org\springframework\boot\spring-boot-starter-jdbc\2.1.7.RELEASE\spring-boot-starter-jdbc-2.1.7.RELEASE.jar;D:\repository\com\zaxxer\HikariCP\3.2.0\HikariCP-3.2.0.jar;D:\repository\org\springframework\spring-jdbc\5.1.9.RELEASE\spring-jdbc-5.1.9.RELEASE.jar;D:\repository\org\springframework\boot\spring-boot-starter-test\2.1.7.RELEASE\spring-boot-starter-test-2.1.7.RELEASE.jar;D:\repository\org\springframework\boot\spring-boot-test\2.1.7.RELEASE\spring-boot-test-2.1.7.RELEASE.jar;D:\repository\org\springframework\boot\spring-boot-test-autoconfigure\2.1.7.RELEASE\spring-boot-test-autoconfigure-2.1.7.RELEASE.jar;D:\repository\com\jayway\jsonpath\json-path\2.4.0\json-path-2.4.0.jar;D:\repository\net\minidev\json-smart\2.3\json-smart-2.3.jar;D:\repository\net\minidev\accessors-smart\1.2\accessors-smart-1.2.jar;D:\repository\org\ow2\asm\asm\5.0.4\asm-5.0.4.jar;D:\repository\org\assertj\assertj-core\3.11.1\assertj-core-3.11.1.jar;D:\repository\org\mockito\mockito-core\2.23.4\mockito-core-2.23.4.jar;D:\repository\net\bytebuddy\byte-buddy\1.9.16\byte-buddy-1.9.16.jar;D:\repository\net\bytebuddy\byte-buddy-agent\1.9.16\byte-buddy-agent-1.9.16.jar;D:\repository\org\objenesis\objenesis\2.6\objenesis-2.6.jar;D:\repository\org\hamcrest\hamcrest-library\1.3\hamcrest-library-1.3.jar;D:\repository\org\skyscreamer\jsonassert\1.5.0\jsonassert-1.5.0.jar;D:\repository\com\vaadin\external\google\android-json\0.0.20131108.vaadin1\android-json-0.0.20131108.vaadin1.jar;D:\repository\org\springframework\spring-core\5.1.9.RELEASE\spring-core-5.1.9.RELEASE.jar;D:\repository\org\springframework\spring-jcl\5.1.9.RELEASE\spring-jcl-5.1.9.RELEASE.jar;D:\repository\org\springframework\spring-test\5.1.9.RELEASE\spring-test-5.1.9.RELEASE.jar;D:\repository\org\xmlunit\xmlunit-core\2.6.3\xmlunit-core-2.6.3.jar;D:\repository\redis\clients\jedis\2.9.3\jedis-2.9.3.jar;D:\repository\org\slf4j\slf4j-api\1.7.26\slf4j-api-1.7.26.jar;D:\repository\org\apache\commons\commons-pool2\2.6.2\commons-pool2-2.6.2.jar;D:\repository\org\junit\platform\junit-platform-launcher\1.3.2\junit-platform-launcher-1.3.2.jar;D:\repository\org\junit\jupiter\junit-jupiter-engine\5.3.2\junit-jupiter-engine-5.3.2.jar;D:\repository\org\junit\jupiter\junit-jupiter-api\5.3.2\junit-jupiter-api-5.3.2.jar;D:\repository\mysql\mysql-connector-java\8.0.17\mysql-connector-java-8.0.17.jar;D:\repository\io\springfox\springfox-swagger2\2.9.2\springfox-swagger2-2.9.2.jar;D:\repository\io\swagger\swagger-annotations\1.5.20\swagger-annotations-1.5.20.jar;D:\repository\io\swagger\swagger-models\1.5.20\swagger-models-1.5.20.jar;D:\repository\com\fasterxml\jackson\core\jackson-annotations\2.9.0\jackson-annotations-2.9.0.jar;D:\repository\io\springfox\springfox-spi\2.9.2\springfox-spi-2.9.2.jar;D:\repository\io\springfox\springfox-core\2.9.2\springfox-core-2.9.2.jar;D:\repository\io\springfox\springfox-schema\2.9.2\springfox-schema-2.9.2.jar;D:\repository\io\springfox\springfox-swagger-common\2.9.2\springfox-swagger-common-2.9.2.jar;D:\repository\io\springfox\springfox-spring-web\2.9.2\springfox-spring-web-2.9.2.jar;D:\repository\com\google\guava\guava\20.0\guava-20.0.jar;D:\repository\com\fasterxml\classmate\1.4.0\classmate-1.4.0.jar;D:\repository\org\springframework\plugin\spring-plugin-core\1.2.0.RELEASE\spring-plugin-core-1.2.0.RELEASE.jar;D:\repository\org\springframework\plugin\spring-plugin-metadata\1.2.0.RELEASE\spring-plugin-metadata-1.2.0.RELEASE.jar;D:\repository\org\mapstruct\mapstruct\1.2.0.Final\mapstruct-1.2.0.Final.jar;D:\repository\io\springfox\springfox-swagger-ui\2.9.2\springfox-swagger-ui-2.9.2.jar;D:\repository\org\apache\commons\commons-lang3\3.9\commons-lang3-3.9.jar;D:\repository\org\springframework\boot\spring-boot-devtools\2.1.7.RELEASE\spring-boot-devtools-2.1.7.RELEASE.jar;D:\repository\org\springframework\boot\spring-boot\2.1.7.RELEASE\spring-boot-2.1.7.RELEASE.jar;D:\repository\org\springframework\boot\spring-boot-autoconfigure\2.1.7.RELEASE\spring-boot-autoconfigure-2.1.7.RELEASE.jar" com.intellij.rt.execution.junit.JUnitStarter -ideVersion5 -junit5 com.zsx.test.mapper.UserMapperTest
09:49:05.191 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating CacheAwareContextLoaderDelegate from class [org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate]
09:49:05.211 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating BootstrapContext using constructor [public org.springframework.test.context.support.DefaultBootstrapContext(java.lang.Class,org.springframework.test.context.CacheAwareContextLoaderDelegate)]
09:49:05.234 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating TestContextBootstrapper for test class [com.zsx.test.mapper.UserMapperTest] from class [org.springframework.boot.test.context.SpringBootTestContextBootstrapper]
09:49:05.248 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Neither @ContextConfiguration nor @ContextHierarchy found for test class [com.zsx.test.mapper.UserMapperTest], using SpringBootContextLoader
09:49:05.250 [main] DEBUG org.springframework.test.context.support.AbstractContextLoader - Did not detect default resource location for test class [com.zsx.test.mapper.UserMapperTest]: class path resource [com/zsx/test/mapper/UserMapperTest-context.xml] does not exist
09:49:05.251 [main] DEBUG org.springframework.test.context.support.AbstractContextLoader - Did not detect default resource location for test class [com.zsx.test.mapper.UserMapperTest]: class path resource [com/zsx/test/mapper/UserMapperTestContext.groovy] does not exist
09:49:05.251 [main] INFO org.springframework.test.context.support.AbstractContextLoader - Could not detect default resource locations for test class [com.zsx.test.mapper.UserMapperTest]: no resource found for suffixes {-context.xml, Context.groovy}.
09:49:05.251 [main] INFO org.springframework.test.context.support.AnnotationConfigContextLoaderUtils - Could not detect default configuration classes for test class [com.zsx.test.mapper.UserMapperTest]: UserMapperTest does not declare any static, non-private, non-final, nested classes annotated with @Configuration.
09:49:05.291 [main] DEBUG org.springframework.test.context.support.ActiveProfilesUtils - Could not find an 'annotation declaring class' for annotation type [org.springframework.test.context.ActiveProfiles] and class [com.zsx.test.mapper.UserMapperTest]
09:49:05.411 [main] DEBUG org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider - Identified candidate component class: file [F:\IdeaProjects\event\target\classes\com\zsx\SpringBootTemplateApplication.class]
09:49:05.412 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Found @SpringBootConfiguration com.zsx.SpringBootTemplateApplication for test class com.zsx.test.mapper.UserMapperTest
09:49:05.498 [main] DEBUG org.springframework.boot.test.context.SpringBootTestContextBootstrapper - @TestExecutionListeners is not present for class [com.zsx.test.mapper.UserMapperTest]: using defaults.
09:49:05.498 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Loaded default TestExecutionListener class names from location [META-INF/spring.factories]: [org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener, org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener, org.springframework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionListener, org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerResetTestExecutionListener, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrintOnlyOnFailureTestExecutionListener, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverTestExecutionListener, org.springframework.test.context.web.ServletTestExecutionListener, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener, org.springframework.test.context.support.DependencyInjectionTestExecutionListener, org.springframework.test.context.support.DirtiesContextTestExecutionListener, org.springframework.test.context.transaction.TransactionalTestExecutionListener, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener]
09:49:05.540 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Using TestExecutionListeners: [org.springframework.test.context.web.ServletTestExecutionListener@7e3181aa, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener@253d9f73, org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener@142269f2, org.springframework.boot.test.autoconfigure.SpringBootDependencyInjectionTestExecutionListener@331acdad, org.springframework.test.context.support.DirtiesContextTestExecutionListener@41d426b5, org.springframework.test.context.transaction.TransactionalTestExecutionListener@8dbfffb, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener@f316aeb, org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener@6aa3a905, org.springframework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionListener@a22cb6a, org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerResetTestExecutionListener@5dd1c9f2, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrintOnlyOnFailureTestExecutionListener@59b38691, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverTestExecutionListener@2e2ff723]
09:49:05.542 [main] DEBUG org.springframework.test.context.support.AbstractDirtiesContextTestExecutionListener - Before test class: context [DefaultTestContext@12ed9db6 testClass = UserMapperTest, testInstance = [null], testMethod = [null], testException = [null], mergedContextConfiguration = [WebMergedContextConfiguration@4ff4357f testClass = UserMapperTest, locations = '{}', classes = '{class com.zsx.SpringBootTemplateApplication}', contextInitializerClasses = '[]', activeProfiles = '{}', propertySourceLocations = '{}', propertySourceProperties = '{org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true}', contextCustomizers = set[org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@19932c16, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@305ffe9e, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, org.springframework.boot.test.web.client.TestRestTemplateContextCustomizer@4bdeaabb, org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@0, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizerFactory$Customizer@4722ef0c], resourceBasePath = 'src/main/webapp', contextLoader = 'org.springframework.boot.test.context.SpringBootContextLoader', parent = [null]], attributes = map['org.springframework.test.context.web.ServletTestExecutionListener.activateListener' -> true]], class annotated with @DirtiesContext [false] with mode [null].
09:49:05.571 [main] DEBUG org.springframework.test.context.support.TestPropertySourceUtils - Adding inlined properties to environment: {spring.jmx.enabled=false, org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true, server.port=-1}
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.1.7.RELEASE)
2019-08-20 09:49:06.172 ----> [main] ---> INFO com.zsx.test.mapper.UserMapperTest - Starting UserMapperTest on zsx with PID 11268 (started by zhang in F:\IdeaProjects\event)
2019-08-20 09:49:06.176 ----> [main] ---> INFO com.zsx.test.mapper.UserMapperTest - The following profiles are active: dev
2019-08-20 09:49:07.084 ----> [main] ---> WARN org.mybatis.spring.mapper.ClassPathMapperScanner - No MyBatis mapper was found in '[com.zsx.dynamic.mapper]' package. Please check your configuration.
2019-08-20 09:49:08.409 ----> [main] ---> INFO com.zsx.config.MybatisDBSecondConfig - ====================
2019-08-20 09:49:08.410 ----> [main] ---> INFO com.zsx.config.MybatisDBSecondConfig - dynamicDataSource=========com.zsx.config.DynamicDataSource@59fea5f5
2019-08-20 09:49:08.598 ----> [main] ---> INFO com.zsx.config.MybatisDBPrimaryConfig - ====================
2019-08-20 09:49:08.599 ----> [main] ---> INFO com.zsx.config.MybatisDBPrimaryConfig - primaryDataSource=========HikariDataSource (null)
2019-08-20 09:49:08.616 ----> [main] ---> INFO com.zsx.config.MybatisDBSecondConfig - ====================
2019-08-20 09:49:08.617 ----> [main] ---> INFO com.zsx.config.MybatisDBSecondConfig - secondDataSource=========HikariDataSource (null)
2019-08-20 09:49:08.633 ----> [main] ---> INFO com.zsx.config.MybatisDBThirdConfig - ====================
2019-08-20 09:49:08.634 ----> [main] ---> INFO com.zsx.config.MybatisDBThirdConfig - thirdDataSource=========HikariDataSource (null)
2019-08-20 09:49:08.715 ----> [main] ---> INFO s.d.s.w.PropertySourcedRequestMappingHandlerMapping - Mapped URL path [/v2/api-docs] onto method [public org.springframework.http.ResponseEntity springfox.documentation.swagger2.web.Swagger2Controller.getDocumentation(java.lang.String,javax.servlet.http.HttpServletRequest)]
2019-08-20 09:49:09.814 ----> [main] ---> INFO s.d.s.web.plugins.DocumentationPluginsBootstrapper - Context refreshed
2019-08-20 09:49:09.846 ----> [main] ---> INFO s.d.s.web.plugins.DocumentationPluginsBootstrapper - Found 1 custom documentation plugin(s)
2019-08-20 09:49:09.884 ----> [main] ---> INFO s.d.spring.web.scanners.ApiListingReferenceScanner - Scanning for api listing references
2019-08-20 09:49:10.003 ----> [main] ---> INFO com.zsx.test.mapper.UserMapperTest - Started UserMapperTest in 4.416 seconds (JVM running for 5.691)
2019-08-20 09:49:10.367 ----> [main] ---> INFO com.zaxxer.hikari.HikariDataSource - HikariPool-1 - Starting...
2019-08-20 09:49:10.848 ----> [main] ---> INFO com.zaxxer.hikari.HikariDataSource - HikariPool-1 - Start completed.
User{id=1, name='sunquan'}
2019-08-20 09:49:10.885 ----> [main] ---> INFO com.zaxxer.hikari.HikariDataSource - HikariPool-2 - Starting...
2019-08-20 09:49:10.896 ----> [main] ---> INFO com.zaxxer.hikari.HikariDataSource - HikariPool-2 - Start completed.
User{id=1, name='caocao'}
2019-08-20 09:49:10.897 ----> [main] ---> INFO com.zaxxer.hikari.HikariDataSource - HikariPool-3 - Starting...
2019-08-20 09:49:10.907 ----> [main] ---> INFO com.zaxxer.hikari.HikariDataSource - HikariPool-3 - Start completed.
User{id=1, name='王昭君'}
2019-08-20 09:49:10.934 ----> [Thread-2] ---> INFO com.zaxxer.hikari.HikariDataSource - HikariPool-3 - Shutdown initiated...
2019-08-20 09:49:10.939 ----> [Thread-2] ---> INFO com.zaxxer.hikari.HikariDataSource - HikariPool-3 - Shutdown completed.
2019-08-20 09:49:10.939 ----> [Thread-2] ---> INFO com.zaxxer.hikari.HikariDataSource - HikariPool-2 - Shutdown initiated...
2019-08-20 09:49:10.940 ----> [Thread-2] ---> INFO com.zaxxer.hikari.HikariDataSource - HikariPool-2 - Shutdown completed.
2019-08-20 09:49:10.942 ----> [Thread-2] ---> INFO com.zaxxer.hikari.HikariDataSource - HikariPool-1 - Shutdown initiated...
2019-08-20 09:49:10.943 ----> [Thread-2] ---> INFO com.zaxxer.hikari.HikariDataSource - HikariPool-1 - Shutdown completed.
Process finished with exit code 0
从结果看出配置数据源成功
1. pom.xml添加AOP依赖
org.springframework.boot
spring-boot-starter-aop
2. 添加数据库配置(DataBaseConfig.java)
@Bean(name="dynamicDataSource")
public DataSource dynamicDataSource() {
DynamicDataSource dynamicDataSource = new DynamicDataSource();
DataSource primaryDataSource = primaryDataSource();
//设置默认数据源
dynamicDataSource.setDefaultTargetDataSource(primaryDataSource);
//配置多数据源
Map
3. 动态数据源配置
package com.zsx.config;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.SqlSessionTemplate;
import org.mybatis.spring.annotation.MapperScan;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import javax.sql.DataSource;
@Configuration
@MapperScan(basePackages = {"com.zsx.mapper.dynamic"}, sqlSessionFactoryRef = "dynamicSqlSessionFactory")
public class MybatisDBDynamicConfig {
private static final Logger LOGGER = LoggerFactory.getLogger(MybatisDBSecondConfig.class);
@Bean(name = "dynamicSqlSessionFactory")
public SqlSessionFactory dynamicSqlSessionFactory(@Qualifier("dynamicDataSource") DataSource dynamicDataSource) throws Exception {
LOGGER.info("====================");
LOGGER.info("dynamicDataSource=========" + dynamicDataSource);
SqlSessionFactoryBean factoryBean = new SqlSessionFactoryBean();
factoryBean.setDataSource(dynamicDataSource);
factoryBean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath:mybatis/mapper/dynamic/*.xml"));
return factoryBean.getObject();
}
@Bean(name = "dynamicSqlSessionTemplate")
public SqlSessionTemplate dynamicSqlSessionTemplate(@Qualifier("dynamicSqlSessionFactory") SqlSessionFactory sqlSessionFactory) {
return new SqlSessionTemplate(sqlSessionFactory);
}
@Bean(name = "dynamicTransactionManager")
public DataSourceTransactionManager dynamicTransactionManager(@Qualifier("dynamicDataSource") DataSource dynamicDataSource) {
return new DataSourceTransactionManager(dynamicDataSource);
}
}
4. 数据源
package com.zsx.config;
import com.zsx.holder.DataSourceContextHolder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;
public class DynamicDataSource extends AbstractRoutingDataSource {
private final static Logger LOGGER = LoggerFactory.getLogger(DynamicDataSource.class);
@Override
protected Object determineCurrentLookupKey() {
LOGGER.debug("数据源为{}", DataSourceContextHolder.getDB());
return DataSourceContextHolder.getDB();
}
}
5. 数据源上下文
package com.zsx.holder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class DataSourceContextHolder {
private final static Logger LOGGER = LoggerFactory.getLogger(DataSourceContextHolder.class);
private final static ThreadLocal contextHolder = new ThreadLocal<>();
// 设置数据源名
public static void setDB(String dbType) {
LOGGER.debug("切换到{}数据源", dbType);
contextHolder.set(dbType);
}
// 获取数据源名
public static String getDB() {
return (contextHolder.get());
}
// 清除数据源名
public static void clearDB() {
contextHolder.remove();
}
}
6. 创建注解接口
package com.zsx.annotation;
import java.lang.annotation.*;
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD, ElementType.TYPE})
@Documented
public @interface DS {
String value() default "primaryDataSource";
}
7. 创建动态数据源切面
package com.zsx.aop;
import com.zsx.annotation.DS;
import com.zsx.holder.DataSourceContextHolder;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
@Aspect
@Order(-1) // 该切面应当先于 @Transactional 执行
@Component
public class DynamicDataSourceAspect {
private final static Logger LOGGER = LoggerFactory.getLogger(DynamicDataSourceAspect.class);
@Before("@annotation(ds)")
public void beforeSwitchDS(JoinPoint point, DS ds) {
LOGGER.info("==========DynamicDataSourceAspect.beforeSwitchDS================");
LOGGER.info("ds.value================" + ds.value());
// 切换数据源
DataSourceContextHolder.setDB(ds.value());
}
@After("@annotation(ds)")
public void afterSwitchDS(JoinPoint point, DS ds) {
LOGGER.info("==========DynamicDataSourceAspect.afterSwitchDS================");
LOGGER.info("ds.value================" + ds.value());
DataSourceContextHolder.clearDB();
}
}
8. 编写数据接口
package com.zsx.mapper.dynamic;
import com.zsx.annotation.DS;
import com.zsx.entity.User;
import org.springframework.stereotype.Repository;
@Repository("userMapper1")
public interface UserMapper {
@DS
User findById(Integer id);
@DS("firstDataSource")
User findById1(Integer id);
@DS("secondDataSource")
User findById2(Integer id);
@DS("thirdDataSource")
User findById3(Integer id);
@DS("fourthDataSource")
User findById4(Integer id);
}
9. 添加对应的映射文件(resources\mybatis\mapper\dynamic\user-mapper.xml)
10. 修改引导类
package com.zsx;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
/**
* 通过配置多数据源,实现动态数据源切换
* 禁用掉spring boot自带的数据源处理类DataSourceAutoConfiguration
*/
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
@MapperScan(value = "com.zsx.dynamic.mapper")
public class SpringBootTemplateApplication {
public static void main(String[] args) {
SpringApplication.run(SpringBootTemplateApplication.class, args);
}
}
11. 测试类
package com.zsx.test.mapper.dynamic;
import com.zsx.mapper.dynamic.UserMapper;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit.jupiter.SpringExtension;
@ExtendWith(SpringExtension.class)
@SpringBootTest
public class UserMapperTest {
@Autowired
@Qualifier("userMapper1")
private UserMapper userMapper;
@Test
void testFindById() {
System.out.println(userMapper.findById(1));
System.out.println(userMapper.findById1(1));
System.out.println(userMapper.findById2(1));
System.out.println(userMapper.findById3(1));
System.out.println(userMapper.findById4(1));
}
}
12. 运行测试方法,查看测试结果
C:\software\jdk-11.0.3\bin\java.exe -ea -Didea.test.cyclic.buffer.size=1048576 "-javaagent:C:\software\JetBrains\IntelliJ IDEA 2019.1.3\lib\idea_rt.jar=18432:C:\software\JetBrains\IntelliJ IDEA 2019.1.3\bin" -Dfile.encoding=UTF-8 -classpath "C:\software\JetBrains\IntelliJ IDEA 2019.1.3\lib\idea_rt.jar;C:\software\JetBrains\IntelliJ IDEA 2019.1.3\plugins\junit\lib\junit-rt.jar;C:\software\JetBrains\IntelliJ IDEA 2019.1.3\plugins\junit\lib\junit5-rt.jar;D:\repository\org\junit\vintage\junit-vintage-engine\5.3.2\junit-vintage-engine-5.3.2.jar;D:\repository\org\apiguardian\apiguardian-api\1.0.0\apiguardian-api-1.0.0.jar;D:\repository\org\junit\platform\junit-platform-engine\1.3.2\junit-platform-engine-1.3.2.jar;D:\repository\org\junit\platform\junit-platform-commons\1.3.2\junit-platform-commons-1.3.2.jar;D:\repository\org\opentest4j\opentest4j\1.1.1\opentest4j-1.1.1.jar;D:\repository\junit\junit\4.12\junit-4.12.jar;D:\repository\org\hamcrest\hamcrest-core\1.3\hamcrest-core-1.3.jar;F:\IdeaProjects\event\target\test-classes;F:\IdeaProjects\event\target\classes;D:\repository\org\springframework\boot\spring-boot-starter-web\2.1.7.RELEASE\spring-boot-starter-web-2.1.7.RELEASE.jar;D:\repository\org\springframework\boot\spring-boot-starter\2.1.7.RELEASE\spring-boot-starter-2.1.7.RELEASE.jar;D:\repository\org\springframework\boot\spring-boot-starter-logging\2.1.7.RELEASE\spring-boot-starter-logging-2.1.7.RELEASE.jar;D:\repository\ch\qos\logback\logback-classic\1.2.3\logback-classic-1.2.3.jar;D:\repository\ch\qos\logback\logback-core\1.2.3\logback-core-1.2.3.jar;D:\repository\org\apache\logging\log4j\log4j-to-slf4j\2.11.2\log4j-to-slf4j-2.11.2.jar;D:\repository\org\apache\logging\log4j\log4j-api\2.11.2\log4j-api-2.11.2.jar;D:\repository\org\slf4j\jul-to-slf4j\1.7.26\jul-to-slf4j-1.7.26.jar;D:\repository\javax\annotation\javax.annotation-api\1.3.2\javax.annotation-api-1.3.2.jar;D:\repository\org\yaml\snakeyaml\1.23\snakeyaml-1.23.jar;D:\repository\org\springframework\boot\spring-boot-starter-json\2.1.7.RELEASE\spring-boot-starter-json-2.1.7.RELEASE.jar;D:\repository\com\fasterxml\jackson\core\jackson-databind\2.9.9\jackson-databind-2.9.9.jar;D:\repository\com\fasterxml\jackson\core\jackson-core\2.9.9\jackson-core-2.9.9.jar;D:\repository\com\fasterxml\jackson\datatype\jackson-datatype-jdk8\2.9.9\jackson-datatype-jdk8-2.9.9.jar;D:\repository\com\fasterxml\jackson\datatype\jackson-datatype-jsr310\2.9.9\jackson-datatype-jsr310-2.9.9.jar;D:\repository\com\fasterxml\jackson\module\jackson-module-parameter-names\2.9.9\jackson-module-parameter-names-2.9.9.jar;D:\repository\org\springframework\boot\spring-boot-starter-tomcat\2.1.7.RELEASE\spring-boot-starter-tomcat-2.1.7.RELEASE.jar;D:\repository\org\apache\tomcat\embed\tomcat-embed-core\9.0.22\tomcat-embed-core-9.0.22.jar;D:\repository\org\apache\tomcat\embed\tomcat-embed-el\9.0.22\tomcat-embed-el-9.0.22.jar;D:\repository\org\apache\tomcat\embed\tomcat-embed-websocket\9.0.22\tomcat-embed-websocket-9.0.22.jar;D:\repository\org\hibernate\validator\hibernate-validator\6.0.17.Final\hibernate-validator-6.0.17.Final.jar;D:\repository\javax\validation\validation-api\2.0.1.Final\validation-api-2.0.1.Final.jar;D:\repository\org\jboss\logging\jboss-logging\3.3.2.Final\jboss-logging-3.3.2.Final.jar;D:\repository\org\springframework\spring-web\5.1.9.RELEASE\spring-web-5.1.9.RELEASE.jar;D:\repository\org\springframework\spring-beans\5.1.9.RELEASE\spring-beans-5.1.9.RELEASE.jar;D:\repository\org\springframework\spring-webmvc\5.1.9.RELEASE\spring-webmvc-5.1.9.RELEASE.jar;D:\repository\org\springframework\spring-context\5.1.9.RELEASE\spring-context-5.1.9.RELEASE.jar;D:\repository\org\springframework\spring-expression\5.1.9.RELEASE\spring-expression-5.1.9.RELEASE.jar;D:\repository\org\springframework\boot\spring-boot-starter-aop\2.1.7.RELEASE\spring-boot-starter-aop-2.1.7.RELEASE.jar;D:\repository\org\springframework\spring-aop\5.1.9.RELEASE\spring-aop-5.1.9.RELEASE.jar;D:\repository\org\aspectj\aspectjweaver\1.9.4\aspectjweaver-1.9.4.jar;D:\repository\org\springframework\boot\spring-boot-starter-data-redis\2.1.7.RELEASE\spring-boot-starter-data-redis-2.1.7.RELEASE.jar;D:\repository\org\springframework\data\spring-data-redis\2.1.10.RELEASE\spring-data-redis-2.1.10.RELEASE.jar;D:\repository\org\springframework\data\spring-data-keyvalue\2.1.10.RELEASE\spring-data-keyvalue-2.1.10.RELEASE.jar;D:\repository\org\springframework\data\spring-data-commons\2.1.10.RELEASE\spring-data-commons-2.1.10.RELEASE.jar;D:\repository\org\springframework\spring-tx\5.1.9.RELEASE\spring-tx-5.1.9.RELEASE.jar;D:\repository\org\springframework\spring-oxm\5.1.9.RELEASE\spring-oxm-5.1.9.RELEASE.jar;D:\repository\org\springframework\spring-context-support\5.1.9.RELEASE\spring-context-support-5.1.9.RELEASE.jar;D:\repository\io\lettuce\lettuce-core\5.1.8.RELEASE\lettuce-core-5.1.8.RELEASE.jar;D:\repository\io\netty\netty-common\4.1.38.Final\netty-common-4.1.38.Final.jar;D:\repository\io\netty\netty-handler\4.1.38.Final\netty-handler-4.1.38.Final.jar;D:\repository\io\netty\netty-buffer\4.1.38.Final\netty-buffer-4.1.38.Final.jar;D:\repository\io\netty\netty-codec\4.1.38.Final\netty-codec-4.1.38.Final.jar;D:\repository\io\netty\netty-transport\4.1.38.Final\netty-transport-4.1.38.Final.jar;D:\repository\io\netty\netty-resolver\4.1.38.Final\netty-resolver-4.1.38.Final.jar;D:\repository\io\projectreactor\reactor-core\3.2.11.RELEASE\reactor-core-3.2.11.RELEASE.jar;D:\repository\org\reactivestreams\reactive-streams\1.0.2\reactive-streams-1.0.2.jar;D:\repository\org\mybatis\spring\boot\mybatis-spring-boot-starter\2.0.1\mybatis-spring-boot-starter-2.0.1.jar;D:\repository\org\mybatis\spring\boot\mybatis-spring-boot-autoconfigure\2.0.1\mybatis-spring-boot-autoconfigure-2.0.1.jar;D:\repository\org\mybatis\mybatis\3.5.1\mybatis-3.5.1.jar;D:\repository\org\mybatis\mybatis-spring\2.0.1\mybatis-spring-2.0.1.jar;D:\repository\org\springframework\boot\spring-boot-starter-jdbc\2.1.7.RELEASE\spring-boot-starter-jdbc-2.1.7.RELEASE.jar;D:\repository\com\zaxxer\HikariCP\3.2.0\HikariCP-3.2.0.jar;D:\repository\org\springframework\spring-jdbc\5.1.9.RELEASE\spring-jdbc-5.1.9.RELEASE.jar;D:\repository\org\springframework\boot\spring-boot-starter-test\2.1.7.RELEASE\spring-boot-starter-test-2.1.7.RELEASE.jar;D:\repository\org\springframework\boot\spring-boot-test\2.1.7.RELEASE\spring-boot-test-2.1.7.RELEASE.jar;D:\repository\org\springframework\boot\spring-boot-test-autoconfigure\2.1.7.RELEASE\spring-boot-test-autoconfigure-2.1.7.RELEASE.jar;D:\repository\com\jayway\jsonpath\json-path\2.4.0\json-path-2.4.0.jar;D:\repository\net\minidev\json-smart\2.3\json-smart-2.3.jar;D:\repository\net\minidev\accessors-smart\1.2\accessors-smart-1.2.jar;D:\repository\org\ow2\asm\asm\5.0.4\asm-5.0.4.jar;D:\repository\org\assertj\assertj-core\3.11.1\assertj-core-3.11.1.jar;D:\repository\org\mockito\mockito-core\2.23.4\mockito-core-2.23.4.jar;D:\repository\net\bytebuddy\byte-buddy\1.9.16\byte-buddy-1.9.16.jar;D:\repository\net\bytebuddy\byte-buddy-agent\1.9.16\byte-buddy-agent-1.9.16.jar;D:\repository\org\objenesis\objenesis\2.6\objenesis-2.6.jar;D:\repository\org\hamcrest\hamcrest-library\1.3\hamcrest-library-1.3.jar;D:\repository\org\skyscreamer\jsonassert\1.5.0\jsonassert-1.5.0.jar;D:\repository\com\vaadin\external\google\android-json\0.0.20131108.vaadin1\android-json-0.0.20131108.vaadin1.jar;D:\repository\org\springframework\spring-core\5.1.9.RELEASE\spring-core-5.1.9.RELEASE.jar;D:\repository\org\springframework\spring-jcl\5.1.9.RELEASE\spring-jcl-5.1.9.RELEASE.jar;D:\repository\org\springframework\spring-test\5.1.9.RELEASE\spring-test-5.1.9.RELEASE.jar;D:\repository\org\xmlunit\xmlunit-core\2.6.3\xmlunit-core-2.6.3.jar;D:\repository\redis\clients\jedis\2.9.3\jedis-2.9.3.jar;D:\repository\org\slf4j\slf4j-api\1.7.26\slf4j-api-1.7.26.jar;D:\repository\org\apache\commons\commons-pool2\2.6.2\commons-pool2-2.6.2.jar;D:\repository\org\junit\platform\junit-platform-launcher\1.3.2\junit-platform-launcher-1.3.2.jar;D:\repository\org\junit\jupiter\junit-jupiter-engine\5.3.2\junit-jupiter-engine-5.3.2.jar;D:\repository\org\junit\jupiter\junit-jupiter-api\5.3.2\junit-jupiter-api-5.3.2.jar;D:\repository\mysql\mysql-connector-java\8.0.17\mysql-connector-java-8.0.17.jar;D:\repository\io\springfox\springfox-swagger2\2.9.2\springfox-swagger2-2.9.2.jar;D:\repository\io\swagger\swagger-annotations\1.5.20\swagger-annotations-1.5.20.jar;D:\repository\io\swagger\swagger-models\1.5.20\swagger-models-1.5.20.jar;D:\repository\com\fasterxml\jackson\core\jackson-annotations\2.9.0\jackson-annotations-2.9.0.jar;D:\repository\io\springfox\springfox-spi\2.9.2\springfox-spi-2.9.2.jar;D:\repository\io\springfox\springfox-core\2.9.2\springfox-core-2.9.2.jar;D:\repository\io\springfox\springfox-schema\2.9.2\springfox-schema-2.9.2.jar;D:\repository\io\springfox\springfox-swagger-common\2.9.2\springfox-swagger-common-2.9.2.jar;D:\repository\io\springfox\springfox-spring-web\2.9.2\springfox-spring-web-2.9.2.jar;D:\repository\com\google\guava\guava\20.0\guava-20.0.jar;D:\repository\com\fasterxml\classmate\1.4.0\classmate-1.4.0.jar;D:\repository\org\springframework\plugin\spring-plugin-core\1.2.0.RELEASE\spring-plugin-core-1.2.0.RELEASE.jar;D:\repository\org\springframework\plugin\spring-plugin-metadata\1.2.0.RELEASE\spring-plugin-metadata-1.2.0.RELEASE.jar;D:\repository\org\mapstruct\mapstruct\1.2.0.Final\mapstruct-1.2.0.Final.jar;D:\repository\io\springfox\springfox-swagger-ui\2.9.2\springfox-swagger-ui-2.9.2.jar;D:\repository\org\apache\commons\commons-lang3\3.9\commons-lang3-3.9.jar;D:\repository\org\springframework\boot\spring-boot-devtools\2.1.7.RELEASE\spring-boot-devtools-2.1.7.RELEASE.jar;D:\repository\org\springframework\boot\spring-boot\2.1.7.RELEASE\spring-boot-2.1.7.RELEASE.jar;D:\repository\org\springframework\boot\spring-boot-autoconfigure\2.1.7.RELEASE\spring-boot-autoconfigure-2.1.7.RELEASE.jar" com.intellij.rt.execution.junit.JUnitStarter -ideVersion5 -junit5 com.zsx.test.mapper.dynamic.UserMapperTest,testFindById
10:19:37.474 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating CacheAwareContextLoaderDelegate from class [org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate]
10:19:37.485 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating BootstrapContext using constructor [public org.springframework.test.context.support.DefaultBootstrapContext(java.lang.Class,org.springframework.test.context.CacheAwareContextLoaderDelegate)]
10:19:37.499 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating TestContextBootstrapper for test class [com.zsx.test.mapper.dynamic.UserMapperTest] from class [org.springframework.boot.test.context.SpringBootTestContextBootstrapper]
10:19:37.509 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Neither @ContextConfiguration nor @ContextHierarchy found for test class [com.zsx.test.mapper.dynamic.UserMapperTest], using SpringBootContextLoader
10:19:37.512 [main] DEBUG org.springframework.test.context.support.AbstractContextLoader - Did not detect default resource location for test class [com.zsx.test.mapper.dynamic.UserMapperTest]: class path resource [com/zsx/test/mapper/dynamic/UserMapperTest-context.xml] does not exist
10:19:37.512 [main] DEBUG org.springframework.test.context.support.AbstractContextLoader - Did not detect default resource location for test class [com.zsx.test.mapper.dynamic.UserMapperTest]: class path resource [com/zsx/test/mapper/dynamic/UserMapperTestContext.groovy] does not exist
10:19:37.512 [main] INFO org.springframework.test.context.support.AbstractContextLoader - Could not detect default resource locations for test class [com.zsx.test.mapper.dynamic.UserMapperTest]: no resource found for suffixes {-context.xml, Context.groovy}.
10:19:37.513 [main] INFO org.springframework.test.context.support.AnnotationConfigContextLoaderUtils - Could not detect default configuration classes for test class [com.zsx.test.mapper.dynamic.UserMapperTest]: UserMapperTest does not declare any static, non-private, non-final, nested classes annotated with @Configuration.
10:19:37.544 [main] DEBUG org.springframework.test.context.support.ActiveProfilesUtils - Could not find an 'annotation declaring class' for annotation type [org.springframework.test.context.ActiveProfiles] and class [com.zsx.test.mapper.dynamic.UserMapperTest]
10:19:37.598 [main] DEBUG org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider - Identified candidate component class: file [F:\IdeaProjects\event\target\classes\com\zsx\SpringBootTemplateApplication.class]
10:19:37.598 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Found @SpringBootConfiguration com.zsx.SpringBootTemplateApplication for test class com.zsx.test.mapper.dynamic.UserMapperTest
10:19:37.665 [main] DEBUG org.springframework.boot.test.context.SpringBootTestContextBootstrapper - @TestExecutionListeners is not present for class [com.zsx.test.mapper.dynamic.UserMapperTest]: using defaults.
10:19:37.666 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Loaded default TestExecutionListener class names from location [META-INF/spring.factories]: [org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener, org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener, org.springframework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionListener, org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerResetTestExecutionListener, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrintOnlyOnFailureTestExecutionListener, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverTestExecutionListener, org.springframework.test.context.web.ServletTestExecutionListener, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener, org.springframework.test.context.support.DependencyInjectionTestExecutionListener, org.springframework.test.context.support.DirtiesContextTestExecutionListener, org.springframework.test.context.transaction.TransactionalTestExecutionListener, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener]
10:19:37.680 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Using TestExecutionListeners: [org.springframework.test.context.web.ServletTestExecutionListener@4612b856, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener@22875539, org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener@5674e1f2, org.springframework.boot.test.autoconfigure.SpringBootDependencyInjectionTestExecutionListener@79c7532f, org.springframework.test.context.support.DirtiesContextTestExecutionListener@2a448449, org.springframework.test.context.transaction.TransactionalTestExecutionListener@32f232a5, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener@43f82e78, org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener@e54303, org.springframework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionListener@e8df99a, org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerResetTestExecutionListener@2dc995f4, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrintOnlyOnFailureTestExecutionListener@2f40e5db, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverTestExecutionListener@517566b]
10:19:37.684 [main] DEBUG org.springframework.test.context.support.AbstractDirtiesContextTestExecutionListener - Before test class: context [DefaultTestContext@2eee3069 testClass = UserMapperTest, testInstance = [null], testMethod = [null], testException = [null], mergedContextConfiguration = [WebMergedContextConfiguration@2da59753 testClass = UserMapperTest, locations = '{}', classes = '{class com.zsx.SpringBootTemplateApplication}', contextInitializerClasses = '[]', activeProfiles = '{}', propertySourceLocations = '{}', propertySourceProperties = '{org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true}', contextCustomizers = set[org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@28dcca0c, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@4c163e3, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, org.springframework.boot.test.web.client.TestRestTemplateContextCustomizer@3de8f619, org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@0, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizerFactory$Customizer@d554c5f], resourceBasePath = 'src/main/webapp', contextLoader = 'org.springframework.boot.test.context.SpringBootContextLoader', parent = [null]], attributes = map['org.springframework.test.context.web.ServletTestExecutionListener.activateListener' -> true]], class annotated with @DirtiesContext [false] with mode [null].
10:19:37.704 [main] DEBUG org.springframework.test.context.support.TestPropertySourceUtils - Adding inlined properties to environment: {spring.jmx.enabled=false, org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true, server.port=-1}
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.1.7.RELEASE)
2019-08-20 10:19:38.274 ----> [main] ---> INFO com.zsx.test.mapper.dynamic.UserMapperTest - Starting UserMapperTest on zsx with PID 2636 (started by zhang in F:\IdeaProjects\event)
2019-08-20 10:19:38.275 ----> [main] ---> INFO com.zsx.test.mapper.dynamic.UserMapperTest - The following profiles are active: dev
2019-08-20 10:19:38.927 ----> [main] ---> WARN org.mybatis.spring.mapper.ClassPathMapperScanner - No MyBatis mapper was found in '[com.zsx.dynamic.mapper]' package. Please check your configuration.
2019-08-20 10:19:39.994 ----> [main] ---> INFO com.zsx.config.MybatisDBSecondConfig - ====================
2019-08-20 10:19:39.996 ----> [main] ---> INFO com.zsx.config.MybatisDBSecondConfig - dynamicDataSource=========com.zsx.config.DynamicDataSource@69f9b561
2019-08-20 10:19:40.117 ----> [main] ---> INFO com.zsx.config.MybatisDBPrimaryConfig - ====================
2019-08-20 10:19:40.118 ----> [main] ---> INFO com.zsx.config.MybatisDBPrimaryConfig - primaryDataSource=========HikariDataSource (null)
2019-08-20 10:19:40.140 ----> [main] ---> INFO com.zsx.config.MybatisDBSecondConfig - ====================
2019-08-20 10:19:40.141 ----> [main] ---> INFO com.zsx.config.MybatisDBSecondConfig - secondDataSource=========HikariDataSource (null)
2019-08-20 10:19:40.150 ----> [main] ---> INFO com.zsx.config.MybatisDBThirdConfig - ====================
2019-08-20 10:19:40.151 ----> [main] ---> INFO com.zsx.config.MybatisDBThirdConfig - thirdDataSource=========HikariDataSource (null)
2019-08-20 10:19:40.217 ----> [main] ---> INFO s.d.s.w.PropertySourcedRequestMappingHandlerMapping - Mapped URL path [/v2/api-docs] onto method [public org.springframework.http.ResponseEntity springfox.documentation.swagger2.web.Swagger2Controller.getDocumentation(java.lang.String,javax.servlet.http.HttpServletRequest)]
2019-08-20 10:19:41.154 ----> [main] ---> INFO s.d.s.web.plugins.DocumentationPluginsBootstrapper - Context refreshed
2019-08-20 10:19:41.183 ----> [main] ---> INFO s.d.s.web.plugins.DocumentationPluginsBootstrapper - Found 1 custom documentation plugin(s)
2019-08-20 10:19:41.212 ----> [main] ---> INFO s.d.spring.web.scanners.ApiListingReferenceScanner - Scanning for api listing references
2019-08-20 10:19:41.324 ----> [main] ---> INFO com.zsx.test.mapper.dynamic.UserMapperTest - Started UserMapperTest in 3.612 seconds (JVM running for 4.336)
2019-08-20 10:19:41.620 ----> [main] ---> INFO com.zsx.aop.DynamicDataSourceAspect - ==========DynamicDataSourceAspect.beforeSwitchDS================
2019-08-20 10:19:41.621 ----> [main] ---> INFO com.zsx.aop.DynamicDataSourceAspect - ds.value================primaryDataSource
2019-08-20 10:19:41.633 ----> [main] ---> INFO com.zaxxer.hikari.HikariDataSource - HikariPool-1 - Starting...
2019-08-20 10:19:41.922 ----> [main] ---> INFO com.zaxxer.hikari.HikariDataSource - HikariPool-1 - Start completed.
2019-08-20 10:19:41.952 ----> [main] ---> INFO com.zsx.aop.DynamicDataSourceAspect - ==========DynamicDataSourceAspect.afterSwitchDS================
2019-08-20 10:19:41.953 ----> [main] ---> INFO com.zsx.aop.DynamicDataSourceAspect - ds.value================primaryDataSource
User{id=1, name='sunquan'}
2019-08-20 10:19:41.957 ----> [main] ---> INFO com.zsx.aop.DynamicDataSourceAspect - ==========DynamicDataSourceAspect.beforeSwitchDS================
2019-08-20 10:19:41.957 ----> [main] ---> INFO com.zsx.aop.DynamicDataSourceAspect - ds.value================firstDataSource
2019-08-20 10:19:41.957 ----> [main] ---> INFO com.zaxxer.hikari.HikariDataSource - HikariPool-2 - Starting...
2019-08-20 10:19:41.966 ----> [main] ---> INFO com.zaxxer.hikari.HikariDataSource - HikariPool-2 - Start completed.
2019-08-20 10:19:41.968 ----> [main] ---> INFO com.zsx.aop.DynamicDataSourceAspect - ==========DynamicDataSourceAspect.afterSwitchDS================
2019-08-20 10:19:41.968 ----> [main] ---> INFO com.zsx.aop.DynamicDataSourceAspect - ds.value================firstDataSource
User{id=1, name='liubei'}
2019-08-20 10:19:41.969 ----> [main] ---> INFO com.zsx.aop.DynamicDataSourceAspect - ==========DynamicDataSourceAspect.beforeSwitchDS================
2019-08-20 10:19:41.969 ----> [main] ---> INFO com.zsx.aop.DynamicDataSourceAspect - ds.value================secondDataSource
2019-08-20 10:19:41.969 ----> [main] ---> INFO com.zaxxer.hikari.HikariDataSource - HikariPool-3 - Starting...
2019-08-20 10:19:41.979 ----> [main] ---> INFO com.zaxxer.hikari.HikariDataSource - HikariPool-3 - Start completed.
2019-08-20 10:19:41.981 ----> [main] ---> INFO com.zsx.aop.DynamicDataSourceAspect - ==========DynamicDataSourceAspect.afterSwitchDS================
2019-08-20 10:19:41.981 ----> [main] ---> INFO com.zsx.aop.DynamicDataSourceAspect - ds.value================secondDataSource
User{id=1, name='caocao'}
2019-08-20 10:19:41.981 ----> [main] ---> INFO com.zsx.aop.DynamicDataSourceAspect - ==========DynamicDataSourceAspect.beforeSwitchDS================
2019-08-20 10:19:41.982 ----> [main] ---> INFO com.zsx.aop.DynamicDataSourceAspect - ds.value================thirdDataSource
2019-08-20 10:19:41.982 ----> [main] ---> INFO com.zaxxer.hikari.HikariDataSource - HikariPool-4 - Starting...
2019-08-20 10:19:41.990 ----> [main] ---> INFO com.zaxxer.hikari.HikariDataSource - HikariPool-4 - Start completed.
2019-08-20 10:19:41.991 ----> [main] ---> INFO com.zsx.aop.DynamicDataSourceAspect - ==========DynamicDataSourceAspect.afterSwitchDS================
2019-08-20 10:19:41.992 ----> [main] ---> INFO com.zsx.aop.DynamicDataSourceAspect - ds.value================thirdDataSource
User{id=1, name='王昭君'}
2019-08-20 10:19:41.992 ----> [main] ---> INFO com.zsx.aop.DynamicDataSourceAspect - ==========DynamicDataSourceAspect.beforeSwitchDS================
2019-08-20 10:19:41.992 ----> [main] ---> INFO com.zsx.aop.DynamicDataSourceAspect - ds.value================fourthDataSource
2019-08-20 10:19:41.993 ----> [main] ---> INFO com.zaxxer.hikari.HikariDataSource - HikariPool-5 - Starting...
2019-08-20 10:19:42.002 ----> [main] ---> INFO com.zaxxer.hikari.HikariDataSource - HikariPool-5 - Start completed.
2019-08-20 10:19:42.003 ----> [main] ---> INFO com.zsx.aop.DynamicDataSourceAspect - ==========DynamicDataSourceAspect.afterSwitchDS================
2019-08-20 10:19:42.004 ----> [main] ---> INFO com.zsx.aop.DynamicDataSourceAspect - ds.value================fourthDataSource
User{id=1, name='赵飞燕'}
2019-08-20 10:19:42.024 ----> [Thread-2] ---> INFO com.zaxxer.hikari.HikariDataSource - HikariPool-5 - Shutdown initiated...
2019-08-20 10:19:42.029 ----> [Thread-2] ---> INFO com.zaxxer.hikari.HikariDataSource - HikariPool-5 - Shutdown completed.
2019-08-20 10:19:42.030 ----> [Thread-2] ---> INFO com.zaxxer.hikari.HikariDataSource - HikariPool-4 - Shutdown initiated...
2019-08-20 10:19:42.032 ----> [Thread-2] ---> INFO com.zaxxer.hikari.HikariDataSource - HikariPool-4 - Shutdown completed.
2019-08-20 10:19:42.032 ----> [Thread-2] ---> INFO com.zaxxer.hikari.HikariDataSource - HikariPool-3 - Shutdown initiated...
2019-08-20 10:19:42.034 ----> [Thread-2] ---> INFO com.zaxxer.hikari.HikariDataSource - HikariPool-3 - Shutdown completed.
2019-08-20 10:19:42.035 ----> [Thread-2] ---> INFO com.zaxxer.hikari.HikariDataSource - HikariPool-2 - Shutdown initiated...
2019-08-20 10:19:42.037 ----> [Thread-2] ---> INFO com.zaxxer.hikari.HikariDataSource - HikariPool-2 - Shutdown completed.
2019-08-20 10:19:42.037 ----> [Thread-2] ---> INFO com.zaxxer.hikari.HikariDataSource - HikariPool-1 - Shutdown initiated...
2019-08-20 10:19:42.046 ----> [Thread-2] ---> INFO com.zaxxer.hikari.HikariDataSource - HikariPool-1 - Shutdown completed.
Process finished with exit code 0
到此动态数据源配置完成