SpringBoot启动报错(Cannot determine embedded database driver class for database type NONE)

Springboot启动报错:

Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.tomcat.jdbc.pool.DataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Cannot determine embedded database driver class for database type NONE. If you want an embedded database please put a supported one on the classpath. If you have database settings to be loaded from a particular profile you may need to active it (no profiles are currently active).
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189)
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588)
    ... 24 more
Caused by: org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Cannot determine embedded database driver class for database type NONE. If you want an embedded database please put a supported one on the classpath. If you have database settings to be loaded from a particular profile you may need to active it (no profiles are currently active).
    at org.springframework.boot.autoconfigure.jdbc.DataSourceProperties.determineDriverClassName(DataSourceProperties.java:246)
    at org.springframework.boot.autoconfigure.jdbc.DataSourceProperties.initializeDataSourceBuilder(DataSourceProperties.java:183)
    at org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration.createDataSource(DataSourceConfiguration.java:42)
    at org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration$Tomcat.dataSource(DataSourceConfiguration.java:56)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162)
    ... 25 more

 

有些同学和我一样,写pom.xml时喜欢从已有项目中直接复制过来,这就导致很多没有用到的包也被依赖进去。就比如说上面这个错误,产生的原因是:没有用到数据库也就是说没有配置数据库的相关信息,但是你在pom.xml中却引入了'mybatis-spring-boot-starter ',Springboot会默认需要加载数据库相关的配置。你在配置文件中没有配置数据源就发生了报错。
 

解决方法一:取消Springboot的默认加载配置

@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class, DataSourceTransactionManagerAutoConfiguration.class })

 

解决方法二:在Application.properties配置文件内对数据库信息进行配置。

spring.datasource.url=jdbc:oracle:thin:@127.0.0.1:1521:Product
spring.datasource.username=yyzq
spring.datasource.password=123
spring.datasource.driver-class-name=oracle.jdbc.OracleDriver

 

解决方法三:如果是个小demo,用不到数据库,直接删除mybatis-spring-boot-starter的依赖。

你可能感兴趣的:(java)