Home  >  Forum  >  Spring
Post New Query

Cannot determine embedded database driver class for database type NONE



Asked on March 06, 2017
I am creating spring application. When I start tomcat server, I have following error.

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:483)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162)
... 51 more



Replied on March 17, 2017
Your project is not getting data source properties. If you are using spring boot Data JPA, use properties starting with spring.datasource.*  in application.properties

spring.datasource.driver-class-name= <driver-class-name>
spring.datasource.url= <url>
spring.datasource.username= <username>
spring.datasource.password= <password>

Then spring boot automatically configure database.


We can also fix the error by configuring data source manually using configuration class with @Configuration. 

        @Bean
public DataSource getDataSource() {
   BasicDataSource dataSource = new BasicDataSource();
   dataSource.setDriverClassName(env.getProperty("database.driverClassName"));
   dataSource.setUrl(env.getProperty("database.url"));
   dataSource.setUsername(env.getProperty("database.username"));
   dataSource.setPassword(env.getProperty("database.password"));
   return dataSource;
}




Write Answer








©2019 concretepage.com | Privacy Policy | Contact Us