利用mybatis-plus配置多数据源时,根据官方文档配置好后,服务启动报错:
2020-08-21 20:38:05.346 DEBUG 19584 - [ost-startStop-1] com.ld.base.LordarLogFilter : Initializing filter 'lordarLogFilter'
2020-08-21 20:38:05.346 DEBUG 19584 - [ost-startStop-1] com.ld.base.LordarLogFilter : Filter 'lordarLogFilter' configured successfully
2020-08-21 20:38:05.544 INFO 19584 - [ main] c.a.d.s.b.a.DruidDataSourceAutoConfigure : Init DruidDataSource
2020-08-21 20:38:05.915 WARN 19584 - [ main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'syncOrder': Unsatisfied dependency expressed through field 'transactionlogSfaMapper'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'transactionlogSfaMapper' defined in file [E:\lordar\loreal-dp-online\dp-ticket\deps\dp-ticket-mapper\target\classes\com\ld\mapper\dao\TransactionlogSfaMapper.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [com/baomidou/mybatisplus/autoconfigure/MybatisPlusAutoConfiguration.class]: Unsatisfied dependency expressed through method 'sqlSessionFactory' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [com/alibaba/druid/spring/boot/autoconfigure/DruidDataSourceAutoConfigure.class]: Invocation of init method failed; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Cannot determine embedded database driver class for database type NONE. If you want an embedded database please put a supported one on the classpath. If you have database settings to be loaded from a particular profile you may need to active it (the profiles "dev" are currently active).
2020-08-21 20:38:05.915 INFO 19584 - [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2020-08-21 20:38:06.015 INFO 19584 - [ main] utoConfigurationReportLoggingInitializer :
Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2020-08-21 20:38:06.022 ERROR 19584 - [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
Cannot determine embedded database driver class for database type NONE
Action:
If you want an embedded database please put a supported one on the classpath. If you have database settings to be loaded from a particular profile you may need to active it (the profiles "dev" are currently active).
Disconnected from the target VM, address: '127.0.0.1:55521', transport: 'socket'
Process finished with exit code 1
寻找了好久,在yml文件加上一个配置解决问题:
autoconfigure:
# 为了某些版本的springboot @SpringBootApplication(exclude= {DataSourceAutoConfiguration.class}) 无法生效
# @SpringBootApplication(exclude={DataSourceAutoConfiguration.class})
# 禁止springboot自动注入数据源配置。
# 为了后续利用注解动态传入的参数,对应连接相应数据库。为多数据源连接使用。
exclude: com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure
服务成功启动!