Spring boot Bean exception: Cannot determine embedded database driver class for database type NONE
Solution 1
I found a solution to run my application with Eclipse.
Before I tried to run my application using Java Application -> SpringApplication with the main class: org.springframework.boot.SpringApplication
. Changing the main class to xxx.Application (where xxx is the projectname) works.
Solution 2
package com.fyakuthibernatespringboot.demo;
@SpringBootApplication
@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
Klyner
“Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.”
Updated on September 03, 2022Comments
-
Klyner over 1 year
I am trying to run a spring boot application which is made by someone else. I have tried to attach my local database to the application but when I run this, it gives the following error;
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private javax.sql.DataSource org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration.dataSource; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfiguration$NonEmbeddedConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.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).
I am new to this and I can't find out what is the problem. Some details:
where xxx = name of the database.
Workbench:
Name: Local instance wampmysqld64 Host: localhost Port: 3306 Server: MySQL Community Server (GPL) Version: 5.7.18-log Connector: C++ 1.1.4 Login User: root Current User: root@localhost SSL: Disabled
And the server is up and running.
EDIT
pom.xml
<project> <modelVersion>4.0.0</modelVersion> <groupId>****</groupId> <artifactId>****</artifactId> <version>0.0.1-SNAPSHOT</version> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.3.6.RELEASE</version> </parent> <dependencies> <dependency> <groupId>org.modelmapper</groupId> <artifactId>modelmapper</artifactId> <version>1.1.0</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-rest</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>
EDIT2
Application.properties
spring.datasource.url=jdbc:mysql://localhost:3306/xxx spring.datasource.username=root spring.datasource.password=root spring.jpa.hibernate.ddl-auto=update spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQLDialect spring.jpa.properties.hibernate.id.new_generator_mappings = false spring.jpa.properties.hibernate.format_sql = true logging.level.org.hibernate.SQL=DEBUG logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE
ng.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE
Application.java
package gdprserver; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.data.rest.RepositoryRestMvcAutoConfiguration; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.context.web.SpringBootServletInitializer; import org.springframework.context.annotation.Bean; @SpringBootApplication(exclude = RepositoryRestMvcAutoConfiguration.class) public class Application extends SpringBootServletInitializer { @Override protected SpringApplicationBuilder configure(final SpringApplicationBuilder application) { return application.sources(Application.class); } public static void main(final String[] args) { SpringApplication.run(Application.class, args); } @Bean public ModelMapper modelMapper() { return new ModelMapper(); } }
EDIT3
I run the Spring boot application with CMD using the command:
java -jar xxx.jar
-
sagarr over 6 yearsyou sure your
application.properties
file on classpath (ideally atsrc/main/resources
? Also show your@SpringBootApplication
class -
Klyner over 6 yearsThe application.properties is located at
src/main/resources
yes. -
Gerry Mantha over 6 yearsNo spring-boot-starter-jdbc or spring-boot-starter-data-jpa?
-
Gerry Mantha over 6 yearsAfter fixing your dependencies, if Spring for unknown reasons still can't find the driver class to instantiate (it should deduce it for mySQL from your URL for that driver) you can add a property explicitly naming it like this:
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
-
Klyner over 6 yearsThanks for your help @GerryMantha. Unfortunetally this does not solve the problem.
-
Gerry Mantha over 6 yearsYou should show more of your POM file... at least all the spring-boot/starter stuff. Also did you double check that your driver dependency is indeed being added to your classpath and included in your deployment assembly?
-
Klyner over 6 years@GerryMantha I am sorry, but I do not understand what you mean with that. How can I check this?
-
xerx593 over 6 yearsI am missing a (i think important) property :
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
in your application.properties. (extending Gerry's answer)
-
-
Zoran Pandovski over 4 yearsAdding just a code example without explanation is not very useful.