当前位置: 首页 > 图灵资讯 > 技术篇> Failed to bind properties under 'spring.datasource.primary' to javax.sql.DataSource:报错

Failed to bind properties under 'spring.datasource.primary' to javax.sql.DataSource:报错

来源:图灵教育
时间:2023-06-11 09:20:25

2023-06-10 11:04:13.778 WARN 22452 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'empController': Unsatisfied dependency expressed through field 'empService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'empServiceImpl': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'empMapper' defined in file [F:FTMPCode2306hhh\target\classes\com\qqq\wwww\mappers\mapper1EmpMapper.class]: Cannot resolve reference to bean 'primarySqlSessionTemplate' while setting bean property 'sqlSessionTemplate'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'primarySqlSessionTemplate' defined in class path resource [com/qqq/wwww/config/PrimaryDataSourceConfig.class]: Unsatisfied dependency expressed through method 'primarySqlSessionTemplate' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'primarySqlSessionFactory' defined in class path resource [com/qqq/wwww/config/PrimaryDataSourceConfig.class]: Unsatisfied dependency expressed through method 'primarySqlSessionFactory' parameter 0; nested exception is org.springframework.boot.context.properties.ConfigurationPropertiesBindException: Error creating bean with name 'primaryDataSource': Could not bind properties to 'DataSource' : prefix=spring.datasource.primary, ignoreInvalidFields=false, ignoreUnknownFields=true; nested exception is org.springframework.boot.context.properties.bind.BindException: Failed to bind properties under 'spring.datasource.primary' to javax.sql.DataSource2023-06-0 11:04:13.781 INFO 22452 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]2023-06-10 11:04:13.792 INFO 22452 --- [ main] ConditionEvaluationReportLoggingListener : Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.2023-06-10 11:04:13.797 ERROR 22452 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter : ***************************APPLICATION FAILED TO START***************************Description:Failed to bind properties under 'spring.datasource.primary' to javax.sql.DataSource: Property: spring.datasource.primary.driver-class-name Value: com.mysql.cj.jdbc.Driver Origin: class path resource [application.yml]:9:26 Reason: Failed to load driver class com.mysql.cj.jdbc.Driver in either of HikariConfig class loader or Thread context classloaderAction:Update your application's configuration

Failed to bind properties under 'spring.datasource.primary' to javax.sql.DataSource:报错

检查版本

<dependency>            <groupId>mysql</groupId>            <artifactId>mysql-connector-java</artifactId>            <version>5.1.4</version>            <scope>runtime</scope>        </dependency>

去掉

<version>5.1.4</version>

换成

<dependency>            <groupId>mysql</groupId>            <artifactId>mysql-connector-java</artifactId>            <scope>runtime</scope>        </dependency>Failed to bind properties under 

解决问题的原因是版本冲突造成的

成功启动

.   ____          _            __ _ _ /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/  ___)| |_)| | | | | || (_| |  ) ) ) )  '  |_____| .__|_| |_|_| |___, | / / / / ==============================___/__/__/_________________/ :: Spring Boot ::        (v2.3.4.RELEASE)2023-06-10 11:07:08.066  INFO 6192 --- [           main] com.qqq.wwww.WwwwApplication             : Starting WwwwApplication on ThinkPad-Wei with PID 6192 (F:FTMPCode2306hhh\target\classes started by 32656 in F:FTMPCode2306hhh)2023-06-10 11:07:08.071  INFO 6192 --- [           main] com.qqq.wwww.WwwwApplication             : No active profile set, falling back to default profiles: default2023-06-00 11:07:09.614  WARN 6192 --- [           main] o.m.s.mapper.ClassPathMapperScanner      : No MyBatis mapper was found in '[com.**.**.mapper]' package. Please check your configuration.2023-06-10 11:07:10.080  INFO 6192 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 2222 (http)2023-06-10 11:07:10.091  INFO 6192 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]2023-06-10 11:07:10.092  INFO 6192 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.38]2023-06-10 11:07:10.228  INFO 6192 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded Webaplicationtext2023-06-00 11:07:10.228  INFO 6192 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 2066 ms2023-06-10 11:07:11.027  INFO 6192 --- [           main] pertySourcedRequestMappingHandlerMapping : Mapped URL path [/v2/api-docs] onto method [springfox.documentation.swagger2.web.Swagger2Controller#getDocumentation(String, HttpServletRequest)]2023-06-10 11:07:11.123  INFO 6192 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'2023-06-10 11:07:11.398  INFO 6192 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 2222 (http) with context path ''2023-06-10 11:07:11.400  INFO 6192 --- [           main] d.s.w.p.DocumentationPluginsBootstrapper : Context refreshed2023-06-100 11:07:11.421  INFO 6192 --- [           main] d.s.w.p.DocumentationPluginsBootstrapper : Found 1 custom documentation plugin(s)2023-06-10 11:07:11.458  INFO 6192 --- [           main] s.d.s.w.s.ApiListingReferenceScanner     : Scanning for api listing references2023-06- 11:07:11.680  INFO 6192 --- [           main] .d.s.w.r.o.CachingOperationNameGenerator : Generating unique operation named: addUsingPOST_12023-06-10 11:07:11.681  INFO 6192 --- [           main] .d.s.w.r.o.CachingOperationNameGenerator : Generating unique operation named: editUsingPUT_12023-06-10 11:07:11.684  INFO 6192 --- [           main] .d.s.w.r.o.CachingOperationNameGenerator : Generating unique operation named: exportUsingPOST_12023-06-10 11:07:11.686  INFO 6192 --- [           main] .d.s.w.r.o.CachingOperationNameGenerator : Generating unique operation named: getInfoUsingGET_12023-06-10 11:07:11.689  INFO 6192 --- [           main] .d.s.w.r.o.CachingOperationNameGenerator : Generating unique operation named: listUsingGET_12023-06-10 11:07:11.691  INFO 6192 --- [           main] .d.s.w.r.o.CachingOperationNameGenerator : Generating unique operation named: removeUsingDELETE_12023-06-10 11:07:11.711  INFO 6192 --- [           main] com.qqq.wwww.WwwwApplication             : Started WwwwApplication in 4.341 seconds (JVM running for 5.868)