springBoot启动报错解决:Reason: Failed to determine a suitable driver class

启动报错:

[root@node05 nginx]# java -jar demo-1.0.0-SNAPSHOT.jar 

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

2022-05-27 16:48:54.483  INFO 2184 --- [           main] com.example.demo.DemoApplication         : Starting DemoApplication v1.0.0-SNAPSHOT on node05 with PID 2184 (/opt/nginx/demo-1.0.0-SNAPSHOT.jar started by root in /opt/nginx)
2022-05-27 16:48:54.507  INFO 2184 --- [           main] com.example.demo.DemoApplication         : No active profile set, falling back to default profiles: default
2022-05-27 16:48:56.849  INFO 2184 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2022-05-27 16:48:56.907  INFO 2184 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2022-05-27 16:48:56.908  INFO 2184 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.22]
2022-05-27 16:48:57.428  INFO 2184 --- [           main] org.apache.jasper.servlet.TldScanner     : At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
2022-05-27 16:48:57.925  INFO 2184 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2022-05-27 16:48:57.925  INFO 2184 --- [           main] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 3335 ms
2022-05-27 16:48:58.152  WARN 2184 --- [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'testController': Unsatisfied dependency expressed through field 'userService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userService': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userDao' defined in URL [jar:file:/opt/nginx/demo-1.0.0-SNAPSHOT.jar!/BOOT-INF/classes!/com/example/demo/dao/UserDao.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
2022-05-27 16:48:58.154  INFO 2184 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2022-05-27 16:48:58.211  INFO 2184 --- [           main] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2022-05-27 16:48:58.212 ERROR 2184 --- [           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 a suitable driver class


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 (no profiles are currently active).

解决办法:

1、如果不需要数据库,把数据源去掉:

//去掉数据源,只需要添加:exclude = DataSourceAutoConfiguration.class
@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
public class DemoApplication {

  public static void main(String[] args) {
    SpringApplication.run(DemoApplication.class, args);
  }

}

2、如果有数据库,看第二种:


    
        
            org.springframework.boot
            spring-boot-maven-plugin
            
            
                com.example.demo.DemoApplication
            
            
                
                    
                        repackage
                    
                
            
        
    
    
        
            src/main/java
            
                **/*.properties
                **/*.xml
            
            true
        
        
            src/main/resources
            
                *
                */*
            
            true
        
        
            src/main/webapp
            META-INF/resources
            
                **/**
            
        
    

一定要把配置文件编译进去:

没添加前执行打包的图:

springBoot启动报错解决:Reason: Failed to determine a suitable driver class_第1张图片

 没有把配置文件打包进来,所以报错了

 添加了标签打包后:

springBoot启动报错解决:Reason: Failed to determine a suitable driver class_第2张图片

 

你可能感兴趣的:(java,spring,boot,java,后端)