多数据源启动异常:Reason: Failed to determine suitable jdbc url

Blade 已结 3 1689

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

1. 

2. 

3.


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

多数据源启动异常,进行单元测试时却可以正常查询到两个数据源中的表数据。test和dev的配置环境是一致的,但是在进行项目的启动时就会出现

Reason: Failed to determine suitable jdbc url


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

BladeX-Boot   springblade.2.8.1.RELEASE, WINDOW


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

***************************
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).

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

2022-06-01 11:12:04.711  INFO 5808 --- [           main] s.c.l.p.BladePropertySourcePostProcessor : BladePropertySourcePostProcessor process @BladePropertySource bean.
2022-06-01 11:12:05.382  WARN 5808 --- [           main] io.undertow.websockets.jsr               : UT026010: Buffer pool was not set on WebSocketDeploymentInfo, the default pool will be used
2022-06-01 11:12:05.414  INFO 5808 --- [           main] io.undertow.servlet                      : Initializing Spring embedded WebApplicationContext
2022-06-01 11:12:05.414  INFO 5808 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 2657 ms
2022-06-01 11:12:05.679  INFO 5808 --- [           main] c.a.d.s.b.a.DruidDataSourceAutoConfigure : Init DruidDataSource
2022-06-01 11:12:05.882  WARN 5808 --- [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'customWebSocketHandler': Unsatisfied dependency expressed through field 'notificationService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'notificationServiceImpl': Unsatisfied dependency expressed through field 'noticeUserService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'noticeUserServiceImpl': Unsatisfied dependency expressed through field 'baseMapper'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'noticeUserMapper' defined in file [E:\MT-work\workspace_new\blade-branch\multi-data-source\BladeX-Boot\target\classes\org\springblade\modules\desk\mapper\NoticeUserMapper.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.baomidou.mybatisplus.autoconfigure.MybatisPlusAutoConfiguration': Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.baomidou.mybatisplus.autoconfigure.MybatisPlusAutoConfiguration$$EnhancerBySpringCGLIB$$522a15dc]: Constructor threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mybatisPlusInterceptor' defined in class path resource [org/springblade/core/mp/config/MybatisPlusConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor]: Factory method 'mybatisPlusInterceptor' threw exception; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springblade.core.datascope.config.DataScopeConfiguration': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'jdbcTemplate' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/JdbcTemplateConfiguration.class]: Unsatisfied dependency expressed through method 'jdbcTemplate' 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
2022-06-01 11:12:05.898  INFO 5808 --- [           main] ConditionEvaluationReportLoggingListener :

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2022-06-01 11:12:05.914 ERROR 5808 --- [           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).

3条回答
  •  admin
    admin (最佳回答者)
    2022-06-01 18:43

    加上如下配置

    image.png

    1 讨论(2)
  • 提一个小逻辑问题,版本:org.springblade:blade-core-launch:2.8.1RELEASE;

    org.springblade.core.launch.utils.PropsUtils 的setProperty应该得追加一个 !. 如下如blade000.png

    blade001.png

    blade002.png

    可能新版本已经解决了。

    作者追问:2022-06-02 23:25

    逻辑是没有问题的,props.getProperty返回的是string不是对象。只有当取到的配置为null或者""的时候,才说明没有配置,这样才会变成true,这样才会按照代码内设定的配置去赋值。否则如果命令行有指定,那么这个配置就不是空,那么就会按照命令行的配置来,而不会通过java代码的配置来。否则你加上感叹号,就永远也无法用命令行覆盖java的配置来

    作者追问:2022-06-02 23:30

    具体见图

    image.png

    image.png

    image.png

    1 讨论(0)
  • 2022-06-01 16:30

    我也遇到这个错了,你解决了吗

    0 讨论(0)
提交回复