分库的问题

Blade 未结 2 1696
javahuan
javahuan 剑圣 2021-02-24 18:25

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

 自己做了个分库查询的例子,跑起来没问题,但是按照例子上面的配置放到正式的项目中,跑就出现了问题,maven编译正常,启动时报错如下:

2021-02-24 18:10:45.081  WARN 13500 --- [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'homePageController' defined in file [C:\lcsysol\bladex\blade-service\lcyj-business\target\classes\org\business\lcyj\charge\controller\HomePageController.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'IHomePageServiceImpl': Unsatisfied dependency expressed through field 'baseMapper'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'xjOrderInfoMapper' defined in file [C:\lcsysol\bladex\blade-service\lcyj-business\target\classes\org\business\lcyj\charge\mapper\XjOrderInfoMapper.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$$63ce6d32]: 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 [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Failed to determine suitable jdbc url

2021-02-24 18:10:45.111  INFO 13500 --- [           main] ConditionEvaluationReportLoggingListener : 


Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.

2021-02-24 18:10:45.116 ERROR 13500 --- [           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).


二,配置文件里面做了如下配置


image.png

nacao上面也进行了配置

image.png

自定义的项目pom里面也拉了包
image.png


三,只要我把动态数据源配置去掉,就不报上面的错
image.png

2条回答
  • 2021-02-24 18:42

    看看正式项目有没有这一段配置

    // 开启多数据源
    PropsUtil.setProperty(props, "spring.datasource.dynamic.enabled", "true");


    或者改成覆盖的写法


    props.setProperty("spring.datasource.dynamic.enabled", "true");


    image.png

    作者追问:2021-02-25 11:44

    我加了下面的配置,启动时还是会报上面的错误
    image.png

    回答: 2021-02-25 14:22

    你可以参考下bladex-biz的blade-demo服务配置,跑一跑看看有没问题,没问题的话对比下自己的服务看看有哪里遗漏

    image.png

    image.png

    image.png

    作者追问:2021-02-25 18:33

    我该配置的都配置了啊,而且为了找问题,分库项目里面代码都几乎都注释了,现在的是红箭头这里的问题
    image.png

    换成多数据源配置报错如下

    ***************************

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


    0 讨论(0)
  • 2021-04-27 10:07

    我也遇到了同样的问题,配置检查了无数遍就是起不来。

    0 讨论(0)
提交回复