配置多数据源加载不出数据源的url

Blade 未结 4 6048
渊鱼
渊鱼 剑者 2019-10-17 19:38

一、该问题的重现步骤是什么?

1. 修改默认property数据源配置(只要和默认配置格式不一样)

2. 或者在spring下一层级增加非数据源参数

3.


二、你期待的结果是什么?实际看到的又是什么?

多数据源配置成功,或者在本地配置有spring mail邮件所需参数


三、你正在使用的是什么产品,什么版本?在什么操作系统上?

bladex商业版,包域名自定义


四、请提供详细的错误堆栈信息,这很重要。

019-10-17 19:34:01.771  INFO 14072 --- [           main] faultConfiguringBeanFactoryPostProcessor : No bean named 'errorChannel' has been explicitly defined. Therefore, a default PublishSubscribeChannel will be created.
2019-10-17 19:34:01.800  INFO 14072 --- [           main] faultConfiguringBeanFactoryPostProcessor : No bean named 'integrationHeaderChannelRegistry' has been explicitly defined. Therefore, a default DefaultHeaderChannelRegistry will be created.
2019-10-17 19:34:02.788  INFO 14072 --- [           main] c.a.d.s.b.a.DruidDataSourceAutoConfigure : Init DruidDataSource
2019-10-17 19:34:03.021  WARN 14072 --- [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sentinelBeanPostProcessor' defined in class path resource [com/alibaba/cloud/sentinel/custom/SentinelAutoConfiguration.class]: BeanPostProcessor before instantiation of bean failed; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'transactionAdviceConfig': Unsatisfied dependency expressed through field 'transactionManager'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration$DataSourceTransactionManagerConfiguration': Unsatisfied dependency expressed through constructor 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: Failed to determine suitable jdbc url
2019-10-17 19:34:03.049  INFO 14072 --- [           main] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
Disconnected from the target VM, address: '127.0.0.1:50672', transport: 'socket'
2019-10-17 19:34:03.062 ERROR 14072 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
APPLICATION FAILED TO START
***************************

Description:

Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.

Reason: Failed to determine suitable jdbc url


Action:

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 (the profiles dev are currently active).


Process finished with exit code 1


五、若有更多详细信息,请在下面提供。

#数据源配置
spring:
  datasource:
#    url: ${blade.datasource.dev.url}
#    username: ${blade.datasource.dev.username}
#    password: ${blade.datasource.dev.password}
    dynamic:
      primary: master
      datasource:
        master:
          url: ${blade.datasource.dev.url}
          username: ${blade.datasource.dev.username}
          password: ${blade.datasource.dev.password}
          driver-class-name: com.mysql.cj.jdbc.Driver
        poistore:
          url: ${blade.datasource.dev.ucmurl}
          username: ${blade.datasource.dev.username}
          password: ${blade.datasource.dev.password}
          driver-class-name: com.mysql.cj.jdbc.Driver



4条回答
  • 2020-06-18 11:32

    我也遇到了同样的问题,是这样子解决的分享下

    参考来源于:https://gitee.com/slzh/dynamic-datasource-spring-boot-starter


    解决办法就是 

    @SpringBootApplication(exclude = DruidDataSourceAutoConfigure.class)public class Application {


    为什么要排除DruidDataSourceAutoConfigure ?

    DruidDataSourceAutoConfigure会注入一个DataSourceWrapper,其会在原生的spring.datasource下找url,username,password等。而我们动态数据源的配置路径是变化的。


    3 讨论(1)
  • 2019-10-21 15:32

    可以参考bladex-biz的blade-demo模块的配置

    作者追问:2019-10-21 16:52

    那个里面配置和bladex一样的 没有多数据源配置,也没有看到有禁用默认数据源的配置

    0 讨论(0)
  • 2019-11-11 11:17

    楼主最后怎么解决的?我遇到了同样的问题。求指教

    0 讨论(0)
  • 2022-01-08 22:34

    像楼主说的按照demo配置dev正常,但prod环境需要按“冰心”说的启动类额外加注解@SpringBootApplication(exclude = DruidDataSourceAutoConfigure.class)启动类加注解后,我在生存环境试了,一切正常

    0 讨论(0)
提交回复