If you are reading this, then I think you have got “Cannot determine embedded database driver class for database type NONE” error while running Spring Boot application. Below image shows my simple Spring Boot starter project where I got “Cannot determine embedded database driver class for database type NONE” error while running the JUnit test case.

如果您正在阅读本文,那么我认为运行Spring Boot应用程序时会出现“无法确定数据库类型NONE的嵌入式数据库驱动程序类”错误。 下图显示了我的简单Spring Boot入门项目,在运行JUnit测试用例时,出现“ 无法确定数据库类型NONE的嵌入式数据库驱动程序类 ”错误。

无法确定数据库类型NONE的嵌入式数据库驱动程序类 (Cannot determine embedded database driver class for database type NONE)

This error comes when you don’t have a DataSource configured for your spring boot application. When you run spring boot application, it tries to configure the DataSource and throws this error message when there is no configuration provided.

当您没有为Spring Boot应用程序配置数据源时,就会出现此错误。 当您运行spring boot应用程序时,它会尝试配置DataSource并在没有提供配置时抛出此错误消息。

Below are the classes that I had in my spring boot starter project.

以下是我在Spring Boot Starter项目中拥有的类。

package com.journaldev.spring;import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplication
public class SpringBatchHelloWorldApplication {public static void main(String[] args) {SpringApplication.run(SpringBatchHelloWorldApplication.class, args);}
}
package com.journaldev.spring;import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;@RunWith(SpringRunner.class)
@SpringBootTest
public class SpringBatchHelloWorldApplicationTests {@Testpublic void contextLoads() {}}

My application.properties file was empty. Now when I execute about JUnit class, it give below error.

我的application.properties文件为空。 现在,当我执行有关JUnit类的操作时,它给出以下错误。

11:42:49.460 [main] DEBUG org.springframework.test.context.junit4.SpringJUnit4ClassRunner - SpringJUnit4ClassRunner constructor called with [class com.journaldev.spring.SpringBatchHelloWorldApplicationTests]
11:42:49.469 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating CacheAwareContextLoaderDelegate from class [org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate]
11:42:49.474 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating BootstrapContext using constructor [public org.springframework.test.context.support.DefaultBootstrapContext(java.lang.Class,org.springframework.test.context.CacheAwareContextLoaderDelegate)]
11:42:49.486 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating TestContextBootstrapper for test class [com.journaldev.spring.SpringBatchHelloWorldApplicationTests] from class [org.springframework.boot.test.context.SpringBootTestContextBootstrapper]
11:42:49.495 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Neither @ContextConfiguration nor @ContextHierarchy found for test class [com.journaldev.spring.SpringBatchHelloWorldApplicationTests], using SpringBootContextLoader
11:42:49.498 [main] DEBUG org.springframework.test.context.support.AbstractContextLoader - Did not detect default resource location for test class [com.journaldev.spring.SpringBatchHelloWorldApplicationTests]: class path resource [com/journaldev/spring/SpringBatchHelloWorldApplicationTests-context.xml] does not exist
11:42:49.498 [main] DEBUG org.springframework.test.context.support.AbstractContextLoader - Did not detect default resource location for test class [com.journaldev.spring.SpringBatchHelloWorldApplicationTests]: class path resource [com/journaldev/spring/SpringBatchHelloWorldApplicationTestsContext.groovy] does not exist
11:42:49.499 [main] INFO org.springframework.test.context.support.AbstractContextLoader - Could not detect default resource locations for test class [com.journaldev.spring.SpringBatchHelloWorldApplicationTests]: no resource found for suffixes {-context.xml, Context.groovy}.
11:42:49.499 [main] INFO org.springframework.test.context.support.AnnotationConfigContextLoaderUtils - Could not detect default configuration classes for test class [com.journaldev.spring.SpringBatchHelloWorldApplicationTests]: SpringBatchHelloWorldApplicationTests does not declare any static, non-private, non-final, nested classes annotated with @Configuration.
11:42:49.532 [main] DEBUG org.springframework.test.context.support.ActiveProfilesUtils - Could not find an 'annotation declaring class' for annotation type [org.springframework.test.context.ActiveProfiles] and class [com.journaldev.spring.SpringBatchHelloWorldApplicationTests]
11:42:49.539 [main] DEBUG org.springframework.core.env.StandardEnvironment - Adding [systemProperties] PropertySource with lowest search precedence
11:42:49.540 [main] DEBUG org.springframework.core.env.StandardEnvironment - Adding [systemEnvironment] PropertySource with lowest search precedence
11:42:49.540 [main] DEBUG org.springframework.core.env.StandardEnvironment - Initialized StandardEnvironment with PropertySources [systemProperties,systemEnvironment]
11:42:49.547 [main] DEBUG org.springframework.core.io.support.PathMatchingResourcePatternResolver - Resolved classpath location [com/journaldev/spring/] to resources [URL [file:/Users/pankaj/CODE/hackathon/SpringBatchHelloWorld/target/test-classes/com/journaldev/spring/], URL [file:/Users/pankaj/CODE/hackathon/SpringBatchHelloWorld/target/classes/com/journaldev/spring/]]
11:42:49.548 [main] DEBUG org.springframework.core.io.support.PathMatchingResourcePatternResolver - Looking for matching resources in directory tree [/Users/pankaj/CODE/hackathon/SpringBatchHelloWorld/target/test-classes/com/journaldev/spring]
11:42:49.548 [main] DEBUG org.springframework.core.io.support.PathMatchingResourcePatternResolver - Searching directory [/Users/pankaj/CODE/hackathon/SpringBatchHelloWorld/target/test-classes/com/journaldev/spring] for files matching pattern [/Users/pankaj/CODE/hackathon/SpringBatchHelloWorld/target/test-classes/com/journaldev/spring/*.class]
11:42:49.551 [main] DEBUG org.springframework.core.io.support.PathMatchingResourcePatternResolver - Looking for matching resources in directory tree [/Users/pankaj/CODE/hackathon/SpringBatchHelloWorld/target/classes/com/journaldev/spring]
11:42:49.551 [main] DEBUG org.springframework.core.io.support.PathMatchingResourcePatternResolver - Searching directory [/Users/pankaj/CODE/hackathon/SpringBatchHelloWorld/target/classes/com/journaldev/spring] for files matching pattern [/Users/pankaj/CODE/hackathon/SpringBatchHelloWorld/target/classes/com/journaldev/spring/*.class]
11:42:49.551 [main] DEBUG org.springframework.core.io.support.PathMatchingResourcePatternResolver - Resolved location pattern [classpath*:com/journaldev/spring/*.class] to resources [file [/Users/pankaj/CODE/hackathon/SpringBatchHelloWorld/target/test-classes/com/journaldev/spring/SpringBatchHelloWorldApplicationTests.class], file [/Users/pankaj/CODE/hackathon/SpringBatchHelloWorld/target/classes/com/journaldev/spring/SpringBatchHelloWorldApplication.class]]
11:42:49.589 [main] DEBUG org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider - Identified candidate component class: file [/Users/pankaj/CODE/hackathon/SpringBatchHelloWorld/target/classes/com/journaldev/spring/SpringBatchHelloWorldApplication.class]
11:42:49.590 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Found @SpringBootConfiguration com.journaldev.spring.SpringBatchHelloWorldApplication for test class com.journaldev.spring.SpringBatchHelloWorldApplicationTests
11:42:49.592 [main] DEBUG org.springframework.boot.test.context.SpringBootTestContextBootstrapper - @TestExecutionListeners is not present for class [com.journaldev.spring.SpringBatchHelloWorldApplicationTests]: using defaults.
11:42:49.597 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Loaded default TestExecutionListener class names from location [META-INF/spring.factories]: [org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener, org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener, org.springframework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionListener, org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerResetTestExecutionListener, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrintOnlyOnFailureTestExecutionListener, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverTestExecutionListener, org.springframework.test.context.web.ServletTestExecutionListener, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener, org.springframework.test.context.support.DependencyInjectionTestExecutionListener, org.springframework.test.context.support.DirtiesContextTestExecutionListener, org.springframework.test.context.transaction.TransactionalTestExecutionListener, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener]
11:42:49.612 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Could not instantiate TestExecutionListener [org.springframework.test.context.web.ServletTestExecutionListener]. Specify custom listener classes or make the default listener classes (and their required dependencies) available. Offending class: [javax/servlet/ServletContext]
11:42:49.612 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Using TestExecutionListeners: [org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener@587d1d39, org.springframework.boot.test.autoconfigure.SpringBootDependencyInjectionTestExecutionListener@58c1670b, org.springframework.test.context.support.DirtiesContextTestExecutionListener@6b57696f, org.springframework.test.context.transaction.TransactionalTestExecutionListener@5bb21b69, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener@6b9651f3, org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener@38bc8ab5, org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener@687080dc, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrintOnlyOnFailureTestExecutionListener@23d2a7e8, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverTestExecutionListener@7a9273a8, org.springframework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionListener@26a7b76d, org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerResetTestExecutionListener@4abdb505]
11:42:49.613 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved @ProfileValueSourceConfiguration [null] for test class [com.journaldev.spring.SpringBatchHelloWorldApplicationTests]
11:42:49.614 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved ProfileValueSource type [class org.springframework.test.annotation.SystemProfileValueSource] for class [com.journaldev.spring.SpringBatchHelloWorldApplicationTests]
11:42:49.623 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved @ProfileValueSourceConfiguration [null] for test class [com.journaldev.spring.SpringBatchHelloWorldApplicationTests]
11:42:49.623 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved ProfileValueSource type [class org.springframework.test.annotation.SystemProfileValueSource] for class [com.journaldev.spring.SpringBatchHelloWorldApplicationTests]
11:42:49.624 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved @ProfileValueSourceConfiguration [null] for test class [com.journaldev.spring.SpringBatchHelloWorldApplicationTests]
11:42:49.624 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved ProfileValueSource type [class org.springframework.test.annotation.SystemProfileValueSource] for class [com.journaldev.spring.SpringBatchHelloWorldApplicationTests]
11:42:49.624 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved @ProfileValueSourceConfiguration [null] for test class [com.journaldev.spring.SpringBatchHelloWorldApplicationTests]
11:42:49.624 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved ProfileValueSource type [class org.springframework.test.annotation.SystemProfileValueSource] for class [com.journaldev.spring.SpringBatchHelloWorldApplicationTests]
11:42:49.627 [main] DEBUG org.springframework.test.context.support.AbstractDirtiesContextTestExecutionListener - Before test class: context [DefaultTestContext@69b0fd6f testClass = SpringBatchHelloWorldApplicationTests, testInstance = [null], testMethod = [null], testException = [null], mergedContextConfiguration = [MergedContextConfiguration@757942a1 testClass = SpringBatchHelloWorldApplicationTests, locations = '{}', classes = '{class com.journaldev.spring.SpringBatchHelloWorldApplication}', contextInitializerClasses = '[]', activeProfiles = '{}', propertySourceLocations = '{}', propertySourceProperties = '{org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true}', contextCustomizers = set[org.springframework.boot.test.context.SpringBootTestContextCustomizer@6ea12c19, org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@174d20a, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@0, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizerFactory$Customizer@4f933fd1], contextLoader = 'org.springframework.boot.test.context.SpringBootContextLoader', parent = [null]]], class annotated with @DirtiesContext [false] with mode [null].
11:42:49.627 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved @ProfileValueSourceConfiguration [null] for test class [com.journaldev.spring.SpringBatchHelloWorldApplicationTests]
11:42:49.627 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved ProfileValueSource type [class org.springframework.test.annotation.SystemProfileValueSource] for class [com.journaldev.spring.SpringBatchHelloWorldApplicationTests]
11:42:49.628 [main] DEBUG org.springframework.test.context.support.DependencyInjectionTestExecutionListener - Performing dependency injection for test context [[DefaultTestContext@69b0fd6f testClass = SpringBatchHelloWorldApplicationTests, testInstance = com.journaldev.spring.SpringBatchHelloWorldApplicationTests@b7dd107, testMethod = [null], testException = [null], mergedContextConfiguration = [MergedContextConfiguration@757942a1 testClass = SpringBatchHelloWorldApplicationTests, locations = '{}', classes = '{class com.journaldev.spring.SpringBatchHelloWorldApplication}', contextInitializerClasses = '[]', activeProfiles = '{}', propertySourceLocations = '{}', propertySourceProperties = '{org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true}', contextCustomizers = set[org.springframework.boot.test.context.SpringBootTestContextCustomizer@6ea12c19, org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@174d20a, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@0, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizerFactory$Customizer@4f933fd1], contextLoader = 'org.springframework.boot.test.context.SpringBootContextLoader', parent = [null]]]].
11:42:49.676 [main] DEBUG org.springframework.core.env.StandardEnvironment - Adding [systemProperties] PropertySource with lowest search precedence
11:42:49.676 [main] DEBUG org.springframework.core.env.StandardEnvironment - Adding [systemEnvironment] PropertySource with lowest search precedence
11:42:49.676 [main] DEBUG org.springframework.core.env.StandardEnvironment - Initialized StandardEnvironment with PropertySources [systemProperties,systemEnvironment]
11:42:49.677 [main] DEBUG org.springframework.core.env.MutablePropertySources - Adding [inline] PropertySource with highest search precedence
11:42:49.681 [main] DEBUG org.springframework.test.context.support.TestPropertySourceUtils - Adding inlined properties to environment: {spring.jmx.enabled=false, org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true, server.port=-1}
11:42:49.681 [main] DEBUG org.springframework.core.env.StandardEnvironment - Adding [Inlined Test Properties] PropertySource with highest search precedence.   ____          _            __ _ _/\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \\\/  ___)| |_)| | | | | || (_| |  ) ) ) )'  |____| .__|_| |_|_| |_\__, | / / / /=========|_|==============|___/=/_/_/_/:: Spring Boot ::        (v1.5.1.RELEASE)2017-03-04 11:42:49.876  INFO 51131 --- [           main] .s.SpringBatchHelloWorldApplicationTests : Starting SpringBatchHelloWorldApplicationTests on pankaj.local with PID 51131 (started by pankaj in /Users/pankaj/CODE/hackathon/SpringBatchHelloWorld)
2017-03-04 11:42:49.877  INFO 51131 --- [           main] .s.SpringBatchHelloWorldApplicationTests : No active profile set, falling back to default profiles: default
2017-03-04 11:42:49.902  INFO 51131 --- [           main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@59474f18: startup date [Sat Mar 04 11:42:49 IST 2017]; root of context hierarchy
2017-03-04 11:42:50.311  WARN 51131 --- [           main] s.c.a.AnnotationConfigApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Tomcat.class]: Bean instantiation via factory method failed; nested exception is 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).
2017-03-04 11:42:50.318  INFO 51131 --- [           main] utoConfigurationReportLoggingInitializer : Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2017-03-04 11:42:50.322 ERROR 51131 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : ***************************
APPLICATION FAILED TO START
***************************Description:Cannot determine embedded database driver class for database type NONEAction: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)..   ____          _            __ _ _/\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \\\/  ___)| |_)| | | | | || (_| |  ) ) ) )'  |____| .__|_| |_|_| |_\__, | / / / /=========|_|==============|___/=/_/_/_/:: Spring Boot ::        (v1.5.1.RELEASE)2017-03-04 11:42:50.347  INFO 51131 --- [           main] .s.SpringBatchHelloWorldApplicationTests : Starting SpringBatchHelloWorldApplicationTests on pankaj.local with PID 51131 (started by pankaj in /Users/pankaj/CODE/hackathon/SpringBatchHelloWorld)
2017-03-04 11:42:50.348  INFO 51131 --- [           main] .s.SpringBatchHelloWorldApplicationTests : No active profile set, falling back to default profiles: default
2017-03-04 11:42:50.349  INFO 51131 --- [           main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@2a448449: startup date [Sat Mar 04 11:42:50 IST 2017]; root of context hierarchy
2017-03-04 11:42:50.475  WARN 51131 --- [           main] s.c.a.AnnotationConfigApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Tomcat.class]: Bean instantiation via factory method failed; nested exception is 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).
2017-03-04 11:42:50.477  INFO 51131 --- [           main] utoConfigurationReportLoggingInitializer : Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2017-03-04 11:42:50.479 ERROR 51131 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : ***************************
APPLICATION FAILED TO START
***************************Description:Cannot determine embedded database driver class for database type NONEAction: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).2017-03-04 11:42:50.486 ERROR 51131 --- [           main] o.s.test.context.TestContextManager      : Caught exception while allowing TestExecutionListener [org.springframework.boot.test.autoconfigure.SpringBootDependencyInjectionTestExecutionListener@58c1670b] to prepare test instance [com.journaldev.spring.SpringBatchHelloWorldApplicationTests@b7dd107]java.lang.IllegalStateException: Failed to load ApplicationContextat org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:124) ~[spring-test-4.3.6.RELEASE.jar:4.3.6.RELEASE]at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:83) ~[spring-test-4.3.6.RELEASE.jar:4.3.6.RELEASE]at org.springframework.boot.test.autoconfigure.SpringBootDependencyInjectionTestExecutionListener.prepareTestInstance(SpringBootDependencyInjectionTestExecutionListener.java:47) ~[spring-boot-test-autoconfigure-1.5.1.RELEASE.jar:1.5.1.RELEASE]at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:230) ~[spring-test-4.3.6.RELEASE.jar:4.3.6.RELEASE]at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:228) [spring-test-4.3.6.RELEASE.jar:4.3.6.RELEASE]at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:287) [spring-test-4.3.6.RELEASE.jar:4.3.6.RELEASE]at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) [junit-4.12.jar:4.12]at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:289) [spring-test-4.3.6.RELEASE.jar:4.3.6.RELEASE]at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:247) [spring-test-4.3.6.RELEASE.jar:4.3.6.RELEASE]at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:94) [spring-test-4.3.6.RELEASE.jar:4.3.6.RELEASE]at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) [junit-4.12.jar:4.12]at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) [junit-4.12.jar:4.12]at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) [junit-4.12.jar:4.12]at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) [junit-4.12.jar:4.12]at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) [junit-4.12.jar:4.12]at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61) [spring-test-4.3.6.RELEASE.jar:4.3.6.RELEASE]at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70) [spring-test-4.3.6.RELEASE.jar:4.3.6.RELEASE]at org.junit.runners.ParentRunner.run(ParentRunner.java:363) [junit-4.12.jar:4.12]at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:191) [spring-test-4.3.6.RELEASE.jar:4.3.6.RELEASE]at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86) [.cp/:na]at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) [.cp/:na]at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459) [.cp/:na]at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675) [.cp/:na]at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382) [.cp/:na]at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192) [.cp/:na]
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Tomcat.class]: Bean instantiation via factory method failed; nested exception is 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.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE]at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1173) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE]at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1067) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE]at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE]at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE]at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE]at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE]at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE]at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE]at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE]at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:866) ~[spring-context-4.3.6.RELEASE.jar:4.3.6.RELEASE]at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542) ~[spring-context-4.3.6.RELEASE.jar:4.3.6.RELEASE]at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:737) ~[spring-boot-1.5.1.RELEASE.jar:1.5.1.RELEASE]at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:370) ~[spring-boot-1.5.1.RELEASE.jar:1.5.1.RELEASE]at org.springframework.boot.SpringApplication.run(SpringApplication.java:314) ~[spring-boot-1.5.1.RELEASE.jar:1.5.1.RELEASE]at org.springframework.boot.test.context.SpringBootContextLoader.loadContext(SpringBootContextLoader.java:120) ~[spring-boot-test-1.5.1.RELEASE.jar:1.5.1.RELEASE]at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:98) ~[spring-test-4.3.6.RELEASE.jar:4.3.6.RELEASE]at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:116) ~[spring-test-4.3.6.RELEASE.jar:4.3.6.RELEASE]... 24 common frames omitted
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) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE]at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE]... 41 common frames omitted
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) ~[spring-boot-autoconfigure-1.5.1.RELEASE.jar:1.5.1.RELEASE]at org.springframework.boot.autoconfigure.jdbc.DataSourceProperties.initializeDataSourceBuilder(DataSourceProperties.java:183) ~[spring-boot-autoconfigure-1.5.1.RELEASE.jar:1.5.1.RELEASE]at org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration.createDataSource(DataSourceConfiguration.java:42) ~[spring-boot-autoconfigure-1.5.1.RELEASE.jar:1.5.1.RELEASE]at org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration$Tomcat.dataSource(DataSourceConfiguration.java:56) ~[spring-boot-autoconfigure-1.5.1.RELEASE.jar:1.5.1.RELEASE]at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_73]at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_73]at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_73]at java.lang.reflect.Method.invoke(Method.java:497) ~[na:1.8.0_73]at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE]... 42 common frames omitted

修复了无法确定数据库类型NONE的嵌入式数据库驱动程序类的问题 (Fix for Cannot determine embedded database driver class for database type NONE)

As you can see that my java classes have nothing, so the error has to do something with Spring Boot. I found two ways we can fix this issue.

如您所见,我的java类没有任何内容,因此该错误与Spring Boot有所关系。 我发现了两种方法可以解决此问题。

  1. Exclude auto configuration of DataSource in the Spring Boot application class. We can do this using EnableAutoConfiguration annotation as shown in below code.

    package com.journaldev.spring;import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;@SpringBootApplication
    @EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})
    public class SpringBatchHelloWorldApplication {public static void main(String[] args) {SpringApplication.run(SpringBatchHelloWorldApplication.class, args);}
    }

    With above configuration, JUnit test case executed fine and no more Cannot determine embedded database driver class for database type NONE error.

    EnableAutoConfiguration批注执行此操作,如下面的代码所示。

    通过上述配置,JUnit测试用例可以很好地执行,并且不再能为数据库类型NONE错误确定嵌入式数据库驱动程序类

  2. Another way to fix this issue is to provide spring.datasource.url in the application.properties file. It worked for me, although I didn’t provided any database username and password.
    spring.datasource.url=jdbc:mysql://localhost/Test_DB

    解决此问题的另一种方法是在application.properties文件中提供spring.datasource.url 。 它对我有用,尽管我没有提供任何数据库用户名和密码。

That’s all for fixing the spring boot datasource error, I hope these fixes will help you in fixing the issue with your spring boot application.

这些都是为了修复Spring Boot数据源错误,我希望这些修复将帮助您解决Spring Boot应用程序的问题。

翻译自: https://www.journaldev.com/13830/spring-boot-cannot-determine-embedded-database-driver-class-for-database-type-none

Spring Boot –无法确定数据库类型NONE的嵌入式数据库驱动程序类相关推荐

  1. Spring Boot Test 进行JPA 测试保存数据到数据库

    在Spring Boot 中,将 @SpringBootTest 注解加载测试类中可以很方便的进行测试. 如果是JPA的数据操作, 则测试方法执行时会报 No EntityManager with a ...

  2. spring boot 教程(五)使用JdbcTemplate访问数据库

    今天用Spring Boot访问一下数据库,并且把数据返回到页面中,进行增删改查操作.主要介绍springboot通过jdbc访问关系型MySQL,通过spring的JdbcTemplate去访问. ...

  3. spring boot没有web.xml,如何向嵌入式的servlet容器中注册servlet组件

    1. Spring boot默认使用Tomcat作为嵌入式的servlet容器,只要引入spring-boot-starter-web依赖,就会默认用Tomcat作为servlet容器. 2. Spr ...

  4. spring boot错误: 找不到或无法加载主类

    eclipse启动spring boot项目时出现问题:springboot错误: 找不到或无法加载主类 解决办法: 通过cmd命令行,进入项目目录进行,mvn clean install 进行编译, ...

  5. android 内嵌 数据库,安卓开发之嵌入式数据库sqlite的操作方法

    安卓App开发经常会需要嵌入式数据库sqlite的辅助,它可以存放我们必要的应用数据,下面介绍下如何使用java连接读取sqlite中的数据. 本文中的代码经本人测试可用,可以参考. 代码如下: DB ...

  6. spring boot 动态切换数据源(数据源信息从数据库中读取)

    项目要求从多个源库(oracle,haha,pg)里面读取schema,table,字段等信息,spring提供了AbstractRoutingDataSource类实现动态数据源,下面就简单介绍一下 ...

  7. java 映射类_将数据库类型映射到具体的Java类

    解 答案比使用getMetaData方法更复杂,因为getMetaData方法返回的整数类型和完整的类名没有直接映射.此解决方案需要两段代码: >实现一个方法来获取java.sql.Types常 ...

  8. Spring Boot错误–创建在类路径资源DataSourceAutoConfiguration中定义的名称为“ dataSource”的bean时出错...

    大家好,如果您使用的是Spring Boot,并且遇到诸如"无法为数据库类型NONE确定嵌入式数据库驱动程序类"或"在类路径资源ataSourceAutoConfigur ...

  9. 【spring boot】Controller @RequestMapping 数据绑定:接收 Date 类型参数时遇错,将 String 类型的参数转换成 Date 类型

    前言 spring boot 2.1.1.RELEASE 遇错 Failed to convert value of type 'java.lang.String' to required type ...

最新文章

  1. 2021年大数据常用语言Scala(五):基础语法学习 字符串
  2. Scikit-learn 更新至 0.24 版,这 10 个新特性你需要了解
  3. 综合应用WPF/WCF/WF/LINQ之八:后台开发人员的Solution
  4. c++语言成绩统计系统数组,急求!!!关于学生成绩管理系统的C++ 结构体数组...
  5. 计算机二级access什么时候报名_全国计算机等级考试什么时候报名
  6. java 取消引用_java代码优化——消除过期的对象引用
  7. layui iframe弹出层高度自适应,并垂直居中
  8. SQL Server-【知识与实战III】年龄查询、条件查询、多表查询、姓氏查询
  9. 机器学习算法 | Python实现k-近邻算法
  10. 基于tesseract_ocr实现图片中汉字辨识
  11. 【PBL项目实战】户外智慧农场项目实战系列——1.阿里云物联网平台的开通与云端可视化应用的新建
  12. 连接数据库,写了一个登录注册界面
  13. 安装Ubuntu16.04视频播放器smplayer
  14. 移动硬盘无法识别是怎么回事?还能数据恢复吗?
  15. TCP/UDP协议常用端口号服务
  16. Appium统计iOS或者Android应用的性能
  17. php条件查询,PHP-----多条件查询(示例代码)
  18. 如何给多个Word文档创建一个有连续页码的目录
  19. Qt窗口设置成透明色方法(窗口设置成透明色结果显示成黑色的解决办法)
  20. ubuntu 常见错误--Could not get lock /var/lib/dpkg/lock

热门文章

  1. [Win系统][临时方案]系统任务管理器不能使用临时性解决方案
  2. inout口简单说明
  3. [转载] Python之NumPy基础:数组与向量化计算
  4. [转载] 利用c/c++编写python模块
  5. 抽象类和接口到底是什么“垃圾“——教你分类
  6. quick-cocos2d-x 游戏开发——StateMachine 状态机
  7. jQuery标题文字淡入淡出显示效果
  8. erase() 返回的是删除此元素之后的下一个元素的迭代器 .xml
  9. 写给嵌入式方向的某些同学 - 基于WINCE系统的程序开发[不完整版]
  10. linux sed 不输出,linux-使用awk和sed消除不必要的输出