WHCSRL 技术网

配置文件正常,数据库连接正常,项目启动时报错 org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBe_m0

问题:配置文件正常时启动时报以下错误

  1. Caused by: 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 a suitable driver class
  2. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1796)
  3. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:595)
  4. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517)
  5. at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323)
  6. at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
  7. at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321)
  8. at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
  9. at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276)
  10. at org.springframework.beans.factory.support.DefaultListableBeanFactory.addCandidateEntry(DefaultListableBeanFactory.java:1503)
  11. at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1467)
  12. at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveMultipleBeans(DefaultListableBeanFactory.java:1386)
  13. at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1245)
  14. at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1207)
  15. at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:885)
  16. at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:789)
  17. ... 106 common frames omitted
  18. Caused by: org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Failed to determine a suitable driver class
  19. at org.springframework.boot.autoconfigure.jdbc.DataSourceProperties.determineDriverClassName(DataSourceProperties.java:233)
  20. at org.springframework.boot.autoconfigure.jdbc.DataSourceProperties.determineUsername(DataSourceProperties.java:327)
  21. at com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceWrapper.afterPropertiesSet(DruidDataSourceWrapper.java:40)
  22. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1855)
  23. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1792)
  24. ... 120 common frames omitted
  25. 2021-10-29 12:28:46.845 INFO [main] org.eclipse.jetty.server.handler.ContextHandler - Stopped o.s.b.w.e.j.JettyEmbeddedWebAppContext@6f106af8{application,/,[file:///C:/Users/itjava/AppData/Local/Temp/jetty-docbase.1459803259348902514.8080/, jar:file:/D:/maven/repository/org/webjars/jquery/2.1.1/jquery-2.1.1.jar!/META-INF/resources, jar:file:/D:/maven/repository/org/webjars/d3js/3.4.11/d3js-3.4.11.jar!/META-INF/resources, jar:file:/D:/maven/repository/io/springfox/springfox-swagger-ui/2.5.0/springfox-swagger-ui-2.5.0.jar!/META-INF/resources],UNAVAILABLE}
  26. 2021-10-29 12:28:46.847 WARN [main] o.s.b.w.s.c.AnnotationConfigServletWebServerApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Jetty web server
  27. 2021-10-29 12:28:46.874 INFO [main] o.s.b.a.l.ConditionEvaluationReportLoggingListener -
  28. Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
  29. 2021-10-29 12:28:46.890 ERROR [main] o.s.b.diagnostics.LoggingFailureAnalysisReporter -
  30. ***************************
  31. APPLICATION FAILED TO START
  32. ***************************
  33. Description:
  34. Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.
  35. Reason: Failed to determine a suitable driver class
  36. Action:
  37. Consider the following:
  38. If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
  39. If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).
  40. Process finished with exit code 1

由于jdbc连接驱动不一致引起的问题
在配置文件中URL中最后拼接:&useSSL=false

推荐阅读