springboot啟動不能加載數據庫驅動Failed to determine a suitable driver class


 1 SLF4J: Class path contains multiple SLF4J bindings.
 2 SLF4J: Found binding in [jar:file:/G:/sharp/repo/ch/qos/logback/logback-classic/1.2.3/logback-classic-1.2.3.jar!/org/slf4j/impl/StaticLoggerBinder.class]
 3 SLF4J: Found binding in [jar:file:/G:/sharp/repo/org/slf4j/slf4j-log4j12/1.7.25/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
 4 SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
 5 SLF4J: Actual binding is of type [ch.qos.logback.classic.util.ContextSelectorStaticBinder]
 6 
 7   .   ____          _            __ _ _
 8  /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
 9 ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
10  \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
11   '  |____| .__|_| |_|_| |_\__, | / / / /
12  =========|_|==============|___/=/_/_/_/
13  :: Spring Boot ::        (v2.1.0.RELEASE)
14 
15 2019-01-09 15:32:12.690  INFO 5044 --- [           main] c.sharp.forward.SharpServiceApplication  : Starting SharpServiceApplication on hh-PC with PID 5044 (G:\worksheet\sharp-service\target\classes started by Administrator in G:\worksheet\sharp-service)
16 2019-01-09 15:32:12.696  INFO 5044 --- [           main] c.sharp.forward.SharpServiceApplication  : No active profile set, falling back to default profiles: default
17 log4j:WARN No appenders could be found for logger (com.alibaba.dubbo.common.logger.LoggerFactory).
18 log4j:WARN Please initialize the log4j system properly.
19 log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
20 2019-01-09 15:32:14.095  INFO 5044 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
21 2019-01-09 15:32:14.113  INFO 5044 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
22 2019-01-09 15:32:14.113  INFO 5044 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/9.0.12
23 2019-01-09 15:32:14.121  INFO 5044 --- [           main] o.a.catalina.core.AprLifecycleListener   : The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [D:\topbandSoft\java\jre1.8\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;D:/topbandSoft/java/jre1.8/bin/server;D:/topbandSoft/java/jre1.8/bin;D:/topbandSoft/java/jre1.8/lib/amd64;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Java\jre7;D:\topbandSoft\java\jdk1.8\bin;D:\topbandSoft\java\jdk1.8\jre\bin;D:\topbandSoft\git\Git\cmd;D:\topbandSoft\svn\bin;D:\topbandSoft\maven\apache-maven-3.3.9-bin\apache-maven-3.3.9\bin;C:\Program Files\bin;D:\topbandSoft\zookeeper/bin;D:\topbandSoft\zookeeper/conf;D:\putty\;D:\topbandSoft\eclipse4.8\eclipse;;.]
24 2019-01-09 15:32:14.217  INFO 5044 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
25 2019-01-09 15:32:14.218  INFO 5044 --- [           main] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 1465 ms
26 2019-01-09 15:32:14.241  INFO 5044 --- [           main] o.s.b.w.servlet.ServletRegistrationBean  : Servlet dispatcherServlet mapped to [/]
27 2019-01-09 15:32:14.245  INFO 5044 --- [           main] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'characterEncodingFilter' to: [/*]
28 2019-01-09 15:32:14.246  INFO 5044 --- [           main] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
29 2019-01-09 15:32:14.246  INFO 5044 --- [           main] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'formContentFilter' to: [/*]
30 2019-01-09 15:32:14.246  INFO 5044 --- [           main] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'requestContextFilter' to: [/*]
31 2019-01-09 15:32:14.288  WARN 5044 --- [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userService': Unsatisfied dependency expressed through field 'userMapper'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userMapper' defined in file [G:\worksheet\sharp-mapper\target\classes\com\sharp\forward\mapper\UserMapper.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [org/mybatis/spring/boot/autoconfigure/MybatisAutoConfiguration.class]: Unsatisfied dependency expressed through method 'sqlSessionFactory' 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 a suitable driver class
32 2019-01-09 15:32:14.289  INFO 5044 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
33 2019-01-09 15:32:14.372  INFO 5044 --- [           main] ConditionEvaluationReportLoggingListener : 
34 
35 Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
36 2019-01-09 15:32:14.374 ERROR 5044 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 
37 
38 ***************************
39 APPLICATION FAILED TO START
40 ***************************
41 
42 Description:
43 
44 Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.
45 
46 Reason: Failed to determine a suitable driver class
47 
48 
49 Action:
50 
51 Consider the following:
52     If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
53     If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).

按照網上各種查找參考https://blog.csdn.net/yl123456654321/article/details/82912901

最終發現問題出在了沒有將配置文件掃描進去,我把它排除了,我的pom.xml中資源的配置如下:

 1 <resources>
 2     <resource>
 3         <directory>src/main/java</directory>
 4         <includes>
 5             <include>**/*.yml</include>
 6             <include>**/*.properties</include>
 7             <include>**/*.xml</include>
 8         </includes>
 9         <filtering>false</filtering>
10     </resource>
11     <resource>
12         <directory>${basedir}/src/main/resources</directory>
13         <excludes>
14                 <!-- <exclude>*.properties</exclude> -->
15                  <!-- <exclude>application-dev.properties</exclude>  -->
16             </excludes>
17         <includes>
18             <include>**/*.yml</include>
19             <include>application.properties</include>
20             <include>application-${profile.active}.properties</include>
21             <include>**/*.xml</include>
22         </includes>
23         <filtering>false</filtering>
24     </resource>
25 </resources>

問題出在上面注釋掉的exclude的配置上,這里理解過濾不正確,我把它排除在外了,參考https://blog.csdn.net/u014756827/article/details/52510899

<include>與<exclude>是用來圈定和排除某一文件目錄下的文件是否是工程資源的。如果<include>與<exclude>划定的范圍存在沖突時,以<exclude>划定的范圍為准。大多數情況下,人們使用<include>和<exclude>是為了配合<filtering>實現過濾特定文件的需要。例如,在一個工程中,src/main/resources目錄下都是工程的資源文件,並不需要<include>和<exclude>再進行划定。但如果我們需要對且僅對其中的jdbc.properties和mail.properties兩個文件進行過濾的話,則需要借助<include>和<exclude>進行如下的配置:

 1     <resources>
 2         <!-- Filter jdbc.properties & mail.properties. NOTE: We don't filter applicationContext-infrastructure.xml, 
 3             let it go with spring's resource process mechanism. -->
 4         <resource>
 5             <directory>src/main/resources</directory>
 6             <filtering>true</filtering>
 7             <includes>
 8                 <include>jdbc.properties</include>
 9                 <include>mail.properties</include>
10             </includes>
11         </resource>
12         <!-- Include other files as resources files. -->
13         <resource>
14             <directory>src/main/resources</directory>
15             <filtering>false</filtering>
16             <excludes>
17                 <exclude>jdbc.properties</exclude>
18                 <exclude>mail.properties</exclude>
19             </excludes>
20         </resource>
21     </resources>

其中第一段<resource>配置聲明:在src/main/resources目錄下,僅jdbc.properties和mail.properties兩個文件是資源文件,然后,這兩個文件需要被過濾。而第二段<resource>配置聲明:同樣在src/main/resources目錄下,除jdbc.properties和mail.properties兩個文件外的其他文件也是資源文件,但是它們不會被過濾。

注釋掉以后,可以加載屬性文件,就可以啟動了


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM