原有springboot+maven多模块项目中,想增加获取另一个数据库的数据,于是增加了dynamic-datasource
的配置,如下:
主pom.xml中增加配置:
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>dynamic-datasource-spring-boot-starter</artifactId>
<version>2.5.7</version>
</dependency>
启动类中增加:
EnableTransactionManagement
@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
@EnableScheduling
@MapperScan(basePackages = {"com.xxx.mapper"})
public class RapidoRestApplication extends SpringBootServletInitializer {
yml配置文件如下:
datasource:
dynamic:
##默认的数据源
primary: master
datasource:
master: #唯一标识 你原来的数据源放在这里个里面
url: jdbc:mysql://192.168.****:3306/rap?autoReconnect=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&&useSSL=false
username: rap
password: 123456
type: com.alibaba.druid.pool.DruidDataSource
driverClassName: com.mysql.cj.jdbc.Driver #这是驱动8.0的,以前版本的记得换
s_log: #唯一标识 日志数据源
url: jdbc:mysql://10.12.0.10:3306/resdb?useUnicode=true&characterEncoding=UTF-8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2b8
username: root
password: 123456
type: com.alibaba.druid.pool.DruidDataSource
driverClassName: com.mysql.cj.jdbc.Driver #这是驱动8.0的,以前版本的记得换
filters: stat
maxActive: 200
initialSize: 30
maxWait: 60000
minIdle: 10
timeBetweenEvictionRunsMillis: 60000
minEvictableIdleTimeMillis: 300000
validationQuery: select 'x'
testWhileIdle: true
testOnBorrow: false
testOnReturn: false
poolPreparedStatements: true
maxOpenPreparedStatements: 20
配置完成后,启动服务报错,如下:
Consider the following:
If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).
2021-12-17 18:58:54.388 [Thread-4] ERROR com.ftsafe.rest.client.ChatClient - executor not accepting a task
java.lang.IllegalStateException: executor not accepting a task
at io.netty.resolver.AddressResolverGroup.getResolver(AddressResolverGroup.java:60)
at io.netty.bootstrap.Bootstrap.doResolveAndConnect0(Bootstrap.java:200)
at io.netty.bootstrap.Bootstrap.access$000(Bootstrap.java:49)
at io.netty.bootstrap.Bootstrap$1.operationComplete(Bootstrap.java:188)