您的位置:首页 > 编程语言 > Java开发

Parameter 1 of constructor in org.springframework.boot.autoconfigure.jdbc.DataSourceInitializerInvok

2018-07-25 15:09 1886 查看

Description:

Parameter 1 of constructor in org.springframework.boot.autoconfigure.jdbc.DataSourceInitializerInvoker required a single bean, but 2 were found:
    - csnDataSourceProperties: defined by method 'dataSourceProperties' in class path resource [com/csair/demo/configuration/CSNDataSourceConfiguration.class]
    - spring.datasource-org.springframework.boot.autoconfigure.jdbc.DataSourceProperties: defined in null


Action:

Consider marking one of the beans as @Primary, updating the consumer to accept multiple beans, or using @Qualifier to identify the bean that should be consumed


15:00:15.895 [main] DEBUG org.springframework.boot.devtools.settings.DevToolsSettings - Included patterns for restart : []
15:00:15.898 [main] DEBUG org.springframework.boot.devtools.settings.DevToolsSettings - Excluded patterns for restart : [/spring-boot-actuator/target/classes/, /spring-boot-devtools/target/classes/, /spring-boot/target/classes/, /spring-boot-starter-[\w-]+/, /spring-boot-autoconfigure/target/classes/, /spring-boot-starter/target/classes/]
15:00:15.899 [main] DEBUG org.springframework.boot.devtools.restart.ChangeableUrls - Matching URLs for reloading : [file:/F:/WorkSpace/csair/chief/target/classes/]

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.0.3.RELEASE)

2018-07-25 15:00:16.467  INFO 6704 --- [  restartedMain] com.csair.demo.Application               : Starting Application on PC-201701182045 with PID 6704 (F:\WorkSpace\csair\chief\target\classes started by Administrator in F:\WorkSpace\csair\chief)
2018-07-25 15:00:16.469  INFO 6704 --- [  restartedMain] com.csair.demo.Application               : No active profile set, falling back to default profiles: default
2018-07-25 15:00:16.535  INFO 6704 --- [  restartedMain] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@665738ec: startup date [Wed Jul 25 15:00:16 CST 2018]; root of context hierarchy
2018-07-25 15:00:17.726  INFO 6704 --- [  restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules found, entering strict repository configuration mode!
2018-07-25 15:00:18.117  INFO 6704 --- [  restartedMain] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$2edbb161] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-07-25 15:00:18.506  INFO 6704 --- [  restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 7070 (http)
2018-07-25 15:00:18.534  INFO 6704 --- [  restartedMain] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2018-07-25 15:00:18.534  INFO 6704 --- [  restartedMain] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.31
2018-07-25 15:00:18.539  INFO 6704 --- [ost-startStop-1] o.a.catalina.core.AprLifecycleListener   : Loaded APR based Apache Tomcat Native library [1.2.14] using APR version [1.6.2].
2018-07-25 15:00:18.539  INFO 6704 --- [ost-startStop-1] o.a.catalina.core.AprLifecycleListener   : APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].
2018-07-25 15:00:18.539  INFO 6704 --- [ost-startStop-1] o.a.catalina.core.AprLifecycleListener   : APR/OpenSSL configuration: useAprConnector [false], useOpenSSL [true]
2018-07-25 15:00:19.571  INFO 6704 --- [ost-startStop-1] o.a.catalina.core.AprLifecycleListener   : OpenSSL successfully initialized [OpenSSL 1.0.2l  25 May 2017]
2018-07-25 15:00:19.647  INFO 6704 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2018-07-25 15:00:19.647  INFO 6704 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 3116 ms
2018-07-25 15:00:19.756  INFO 6704 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean  : Servlet dispatcherServlet mapped to [/]
2018-07-25 15:00:19.759  INFO 6704 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'characterEncodingFilter' to: [/*]
2018-07-25 15:00:19.759  INFO 6704 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2018-07-25 15:00:19.759  INFO 6704 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2018-07-25 15:00:19.759  INFO 6704 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'requestContextFilter' to: [/*]
2018-07-25 15:00:19.890  WARN 6704 --- [  restartedMain] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'appInfoContorller': Unsatisfied dependency expressed through field 'appInfoService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'appInfoServiceImpl': Unsatisfied dependency expressed through field 'appInfoDao'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'appInfoDao' defined in file [F:\WorkSpace\csair\chief\target\classes\com\csair\demo\dao\csn\AppInfoDao.class]: Cannot resolve reference to bean 'csnSqlSessionTemplate' while setting bean property 'sqlSessionTemplate'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'csnSqlSessionTemplate' defined in class path resource [com/csair/demo/configuration/CSNDataSourceConfiguration.class]: Unsatisfied dependency expressed through method 'sessionTemplate' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'csnSqlSessionFactory' defined in class path resource [com/csair/demo/configuration/CSNDataSourceConfiguration.class]: Unsatisfied dependency expressed through method 'sqlSessionFactory' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'csnDataSource' defined in class path resource [com/csair/demo/configuration/CSNDataSourceConfiguration.class]: Initialization of bean failed; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.jdbc.DataSourceInitializerInvoker': Unsatisfied dependency expressed through constructor parameter 1; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type 'org.springframework.boot.autoconfigure.jdbc.DataSourceProperties' available: expected single matching bean but found 2: csnDataSourceProperties,spring.datasource-org.springframework.boot.autoconfigure.jdbc.DataSourceProperties
2018-07-25 15:00:19.892  INFO 6704 --- [  restartedMain] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2018-07-25 15:00:19.906  INFO 6704 --- [  restartedMain] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2018-07-25 15:00:19.911 ERROR 6704 --- [  restartedMain] o.s.b.d.LoggingFailureAnalysisReporter   : 

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

Description:

Parameter 1 of constructor in org.springframework.boot.autoconfigure.jdbc.DataSourceInitializerInvoker required a single bean, but 2 were found:
    - csnDataSourceProperties: defined by method 'dataSourceProperties' in class path resource [com/csair/demo/configuration/CSNDataSourceConfiguration.class]
    - spring.datasource-org.springframework.boot.autoconfigure.jdbc.DataSourceProperties: defined in null


Action:

Consider marking one of the beans as @Primary, updating the consumer to accept multiple beans, or using @Qualifier to identify the bean that should be consumed


Process finished with exit code 0
 

 

项目开始的架构的前辈配的,无xml的ssm框架,拿过来用的时候没怎么弄清配置文件,当时原始项目是对应两个数据库,于是就有了两个DataSourceConfiguration

后来自己写的东西只有一张表,就删掉了一个DataSourceConfiguration,然后就一直报错。。。。最后对比了两张表才发现,其中一张表少了@Primary

于是在所有方法前加一个@Primary就可以了,也与报错信息提供的Action相对应

阅读更多
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐