Spring Boot - Cannot determine embedded database driver class for database type NONE
Asked Answered
K

36

238

This is the error that is thrown when trying to run my web app:

[INFO] WARNING: Nested in 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]: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public javax.sql.DataSource org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration$NonEmbeddedConfiguration.dataSource()] threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Cannot determine embedded database driver class for database type NONE. If you want an embedded database please put a supported one on the classpath.:
    [INFO] org.springframework.beans.factory.BeanCreationException: Cannot determine embedded database driver class for database type NONE. If you want an embedded database please put a supported one on the classpath.
    [INFO]  at org.springframework.boot.autoconfigure.jdbc.DataSourceProperties.getDriverClassName(DataSourceProperties.java:91)
    [INFO]  at org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration$NonEmbeddedConfiguration.dataSource(DataSourceAutoConfiguration.java:100)
    [INFO]  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    [INFO]  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    [INFO]  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    [INFO]  at java.lang.reflect.Method.invoke(Method.java:606)
    [INFO]  at com.google.appengine.tools.development.agent.runtime.Runtime.invoke(Runtime.java:115)
    [INFO]  at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:166)
    [INFO]  at org.springframework.beans.factory.support.ConstructorResolver$3.run(ConstructorResolver.java:580)
    [INFO]  at java.security.AccessController.doPrivileged(Native Method)
    [INFO]  at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:577)
    [INFO]  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1094)
    [INFO]  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:989)
    [INFO]  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504)
    [INFO]  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
    [INFO]  at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)
    [INFO]  at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
    [INFO]  at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)
    [INFO]  at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)
    [INFO]  at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1017)
    [INFO]  at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:960)
    [INFO]  at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:858)
    [INFO]  at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:480)
    [INFO]  at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
    [INFO]  at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:289)
    [INFO]  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1185)
    [INFO]  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
    [INFO]  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
    [INFO]  at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)
    [INFO]  at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
    [INFO]  at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)
    [INFO]  at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)
    [INFO]  at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:370)
    [INFO]  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1094)
    [INFO]  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:989)
    [INFO]  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504)
    [INFO]  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
    [INFO]  at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)
    [INFO]  at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
    [INFO]  at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)
    [INFO]  at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)
    [INFO]  at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:973)
    [INFO]  at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:750)
    [INFO]  at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482)
    [INFO]  at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:683)
    [INFO]  at org.springframework.boot.SpringApplication.run(SpringApplication.java:313)
    [INFO]  at org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:142)
    [INFO]  at org.springframework.boot.legacy.context.web.SpringBootContextLoaderListener.initWebApplicationContext(SpringBootContextLoaderListener.java:60)
    [INFO]  at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)
    [INFO]  at org.mortbay.jetty.handler.ContextHandler.startContext(ContextHandler.java:548)
    [INFO]  at org.mortbay.jetty.servlet.Context.startContext(Context.java:136)
    [INFO]  at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1250)
    [INFO]  at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:517)
    [INFO]  at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:467)
    [INFO]  at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
    [INFO]  at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)
    [INFO]  at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
    [INFO]  at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)
    [INFO]  at org.mortbay.jetty.Server.doStart(Server.java:224)
    [INFO]  at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
    [INFO]  at com.google.appengine.tools.development.JettyContainerService.startContainer(JettyContainerService.java:249)
    [INFO]  at com.google.appengine.tools.development.AbstractContainerService.startup(AbstractContainerService.java:306)
    [INFO]  at com.google.appengine.tools.development.AutomaticInstanceHolder.startUp(AutomaticInstanceHolder.java:26)
    [INFO]  at com.google.appengine.tools.development.AbstractModule.startup(AbstractModule.java:79)
    [INFO]  at com.google.appengine.tools.development.Modules.startup(Modules.java:88)
    [INFO]  at com.google.appengine.tools.development.DevAppServerImpl.doStart(DevAppServerImpl.java:254)
    [INFO]  at com.google.appengine.tools.development.DevAppServerImpl.access$000(DevAppServerImpl.java:47)
    [INFO]  at com.google.appengine.tools.development.DevAppServerImpl$1.run(DevAppServerImpl.java:212)
    [INFO]  at com.google.appengine.tools.development.DevAppServerImpl$1.run(DevAppServerImpl.java:210)
    [INFO]  at java.security.AccessController.doPrivileged(Native Method)
    [INFO]  at com.google.appengine.tools.development.DevAppServerImpl.start(DevAppServerImpl.java:210)
    [INFO]  at com.google.appengine.tools.development.DevAppServerMain$StartAction.apply(DevAppServerMain.java:277)
    [INFO]  at com.google.appengine.tools.util.Parser$ParseResult.applyArgs(Parser.java:48)
    [INFO]  at com.google.appengine.tools.development.DevAppServerMain.run(DevAppServerMain.java:219)
    [INFO]  at com.google.appengine.tools.development.DevAppServerMain.main(DevAppServerMain.java:210)

I believe I have the right combination of datanucleus-appengine and datanucleus jars:

2.1: Requires DataNucleus 3.1.x (core, api-jdo, api-jpa, enhancer). Requires SDK 1.6.4+ Note that this release of Datanucleus is no longer supported by the DataNucleus project

JPA App Config:

@Configuration
@EnableJpaRepositories("demo.core.entity")
@EnableTransactionManagement
class JpaApplicationConfig {
    private static final Logger logger = Logger
            .getLogger(JpaApplicationConfig.class.getName());
    @Bean
    public AbstractEntityManagerFactoryBean entityManagerFactory() {
        logger.info("Loading Entity Manager...");
        LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
        factory.setPersistenceUnitName("transactions-optional");
        return factory;
    }
    @Bean
    public PlatformTransactionManager transactionManager() {
        logger.info("Loading Transaction Manager...");
        JpaTransactionManager txManager = new JpaTransactionManager();
        txManager.setEntityManagerFactory(entityManagerFactory().getObject());
        return txManager;
    }
    @Bean
    public PersistenceExceptionTranslator persistenceExceptionTranslator() {
        return new OpenJpaDialect();
    }
}

Application.java

@Configuration
@ComponentScan
@EnableAutoConfiguration
@RestController
public class Application {

    private static final EntityManagerFactory INSTANCE =
            Persistence.createEntityManagerFactory("transactions-optional");

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

    @RequestMapping("/")
    public String home() {
        return "Hello World";
    }

}

POM:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="...">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.demohq</groupId>
    <artifactId>demo-boot</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>

    <name>demo-boot</name>
    <description>Demo project</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.1.0.BUILD-SNAPSHOT</version>
    </parent>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-legacy</artifactId>
            <version>1.1.0.BUILD-SNAPSHOT</version>
        </dependency>
        <!--<dependency>-->
            <!--<groupId>net.kindleit</groupId>-->
            <!--<artifactId>gae-runtime</artifactId>-->
            <!--<version>${gae.version}</version>-->
            <!--<type>pom</type>-->
            <!--<scope>provided</scope>-->
        <!--</dependency>-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aspects</artifactId>
        </dependency>
        <!--<dependency>-->
            <!--<groupId>org.hsqldb</groupId>-->
            <!--<artifactId>hsqldb</artifactId>-->
            <!--<scope>runtime</scope>-->
        <!--</dependency>-->
        <dependency>
            <groupId>com.google.appengine</groupId>
            <artifactId>appengine-api-labs</artifactId>
            <version>${gae.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.google.appengine</groupId>
            <artifactId>appengine-api-stubs</artifactId>
            <version>${gae.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.google.appengine</groupId>
            <artifactId>appengine-testing</artifactId>
            <version>${gae.version}</version>
            <scope>test</scope>
        </dependency>
        <!-- DataNucleus -->
        <dependency>
            <groupId>org.datanucleus</groupId>
            <artifactId>datanucleus-api-jpa</artifactId>
            <version>${datanucleus.jpa.version}</version>
        </dependency>
        <dependency>
            <groupId>org.datanucleus</groupId>
            <artifactId>datanucleus-core</artifactId>
            <version>${datanucleus.jpa.version}</version>
        </dependency>
        <dependency>
            <groupId>org.datanucleus</groupId>
            <artifactId>datanucleus-enhancer</artifactId>
            <version>${datanucleus.jpa.version}</version>
        </dependency>
        <dependency>
            <groupId>com.google.appengine.orm</groupId>
            <artifactId>datanucleus-appengine</artifactId>
            <version>${datanucleus.version}</version>
            <!-- Need to exclude the enhancer since it interfere with the enhancer plugin. -->
            <exclusions>
                <exclusion>
                    <groupId>org.datanucleus</groupId>
                    <artifactId>datanucleus-enhancer</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>javax.jdo</groupId>
            <artifactId>jdo-api</artifactId>
            <version>3.0.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.geronimo.specs</groupId>
            <artifactId>geronimo-jpa_2.0_spec</artifactId>
            <version>1.1</version>
        </dependency>

        <!-- OpenJPA -->
        <dependency>
            <groupId>org.apache.openjpa</groupId>
            <artifactId>openjpa-persistence</artifactId>
            <version>2.3.0</version>
        </dependency>


    </dependencies>

    <properties>
        <start-class>demo.Application</start-class>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.7</java.version>
        <m2eclipse.wtp.contextRoot>/</m2eclipse.wtp.contextRoot>
        <datanucleus.jpa.version>3.1.1</datanucleus.jpa.version>
        <datanucleus.version>2.1.2</datanucleus.version>
        <gae.version>1.8.8</gae.version>
        <gae.home>${settings.localRepository}/com/google/appengine/appengine-java-sdk/${gae.version}/appengine-java-sdk/appengine-java-sdk-${gae.version}</gae.home>
        <gae.application.version>test</gae.application.version>
        <!--<org.springframework-version>4.0.5.RELEASE</org.springframework-version>-->
    </properties>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <!--
            <plugin>
                <groupId>net.kindleit</groupId>
                <artifactId>maven-gae-plugin</artifactId>
                <version>0.9.6</version>
                <dependencies>
                    <dependency>
                        <groupId>net.kindleit</groupId>
                        <artifactId>gae-runtime</artifactId>
                        <version>${gae.version}</version>
                        <type>pom</type>
                    </dependency>
                </dependencies>
            </plugin>
            -->
            <plugin>
                <groupId>com.google.appengine</groupId>
                <artifactId>appengine-maven-plugin</artifactId>
                <version>${gae.version}</version>
                <configuration>
                    <enableJarClasses>false</enableJarClasses>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-release-plugin</artifactId>
                <configuration>
                    <goals>gae:deploy</goals>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.tomcat.maven</groupId>
                <artifactId>tomcat6-maven-plugin</artifactId>
                <version>2.0</version>
                <configuration>
                    <path>/</path>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.datanucleus</groupId>
                <artifactId>maven-datanucleus-plugin</artifactId>
                <version>${datanucleus.jpa.version}</version>
                <configuration>
                    <api>JPA</api>
                    <!--<mappingIncludes>**/entity/*.class</mappingIncludes>-->
                    <verbose>true</verbose>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>org.datanucleus</groupId>
                        <artifactId>datanucleus-core</artifactId>
                        <version>${datanucleus.jpa.version}</version>
                    </dependency>
                </dependencies>
                <executions>
                    <execution>
                        <phase>compile</phase>
                        <goals>
                            <goal>enhance</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <profiles>
        <!-- We can configure our integration server to activate this profile and 
            perform gae:deploy, thus uploading latest snapshot to the http://1.latest.<applicationName>.appspot.com 
            automatically -->
        <profile>
            <id>integration-build</id>
            <properties>
                <gae.application.version>stage</gae.application.version>
            </properties>
        </profile>

        <!-- This profile will activate automatically during release and upload 
            application to the http://2.latest.<applicationName>.appspot.com (We might 
            want to set the 2nd version as our applications Default version to be accessible 
            at http://<applicationName>.appspot.com) -->
        <profile>
            <id>release-build</id>
            <activation>
                <property>
                    <name>performRelease</name>
                    <value>true</value>
                </property>
            </activation>

            <properties>
                <!-- During release, set application version in appengine-web.xml to 
                    2 -->
                <gae.application.version>release</gae.application.version>
            </properties>
        </profile>
    </profiles>

    <repositories>
        <repository>
            <id>spring-snapshots</id>
            <name>Spring Snapshots</name>
            <url>http://repo.spring.io/snapshot</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
        <repository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>http://repo.spring.io/milestone</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
    </repositories>
    <pluginRepositories>
        <pluginRepository>
            <id>spring-snapshots</id>
            <name>Spring Snapshots</name>
            <url>http://repo.spring.io/snapshot</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </pluginRepository>
        <pluginRepository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>http://repo.spring.io/milestone</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </pluginRepository>
    </pluginRepositories>

</project>

I wonder what could be missing in my app? I followed the instruction from here Using Spring Data JPA on Google Appengine

Katz answered 6/6, 2014 at 5:24 Comment(3)
If I comment out the @EnableAutoConfiguration I get: [INFO] WARNING: failed metricFilter: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'metricFilter' is definedKatz
Here is the complete code: bit.ly/1i53oAqKatz
In my case it was spring-boot-starter-data-jpaPucida
P
194

You haven't provided Spring Boot with enough information to auto-configure a DataSource. To do so, you'll need to add some properties to application.properties with the spring.datasource prefix. Take a look at DataSourceProperties to see all of the properties that you can set.

You'll need to provide the appropriate url and driver class name:

spring.datasource.url = …
spring.datasource.driver-class-name = …
Papandreou answered 6/6, 2014 at 16:3 Comment(5)
not sure what to put here I'm using DataNucleus + Google App EngineKatz
@xybrek Just add application.properties file in your application and add the datasource properties in it.Annettaannette
spring.datasource.url = jdbc:mysql://localhost/abc #spring.datasource.driverClassName = com.mysql.jdbc.Driver spring.datasource.name=olabsenglishdb spring.datasource.username=xxxx spring.datasource.password=xxxx spring.datasource.driver-class-name= com.mysql.jdbc.Driver spring.jpa.database=mysql spring.jpa.database-platform=org.hibernate.dialect.MySQLDialectCarlyn
I did the same, the code is working fine when i run the application in intellij but when i create a jar and run it using java -jar myJar.jar it is giving me same error.Guacin
What if one does want to configure the datasource on runtime?Shaniceshanie
V
121

If you want to use embedded H2 database from Spring Boot starter add the below dependency to your pom file.

    <dependency>
        <groupId>com.h2database</groupId>
        <artifactId>h2</artifactId>
        <version>1.3.156</version>
    </dependency>

But as mentioned in comments, the embedded H2 database keeps data in memory and doesn't stores it permanently.

Vouvray answered 16/8, 2014 at 13:1 Comment(9)
I was having the same problem with spring-boot-starter-jdbc. Tried this suggestion and it fixed my problem.Liberati
This is not a real solution. H2 will not permanently save data as far as I'm aware.Coricoriaceous
@Coricoriaceous - Of course it wont! It's an "in memory" database.Vouvray
@user672009, incorrect. H2 is not only an in memory database. See h2database.com/html/features.html. With that said, this is a poor solution to the problem.Broucek
I'm trying to build somebody's app and I get this "Cannot determine ... for database type NONE" error. After trying other solutions, I try this one and it works. The app was made to use two DBs, configured by properties. I configured them, but got this error. After I add the H2 dependency, no more errors. The app uses the other DBs I specified, nothing ever goes to H2, AFAICT. May be a side-effect of spring-boot or a problem in this app's design, but it requires H2 before it will start. Since others have this problem, it can't be just this app.Risorgimento
This one is working , I was using a newer one 1.4.xx but it seems that other configuration is required to set that one up , at least in my Spring boot projectInevitable
No need to have version since spring boot already included with versionLaius
Not a proper solution for problem of a main question, but if you're facing that issue during writing tests (like I did), then IMO this is pretty good solution.Plebeian
H2 artifact in pom did solve the problem for me too. But I needed to work with different DB, So I replaced H2 artifact with postgresql artifact and it worked as well. The issue is that spring needs to know which DB it is and there is no default. So you just need to get the correct DB artifact into your pom file and that should resolve your issueTakeoff
D
96

I'd the same problem and excluding the DataSourceAutoConfiguration solved the problem.

@SpringBootApplication
@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})
public class RecommendationEngineWithCassandraApplication {

    public static void main(String[] args) {
        SpringApplication.run(RecommendationEngineWithCassandraApplication.class, args);
    }
}
Deliberation answered 19/8, 2015 at 12:28 Comment(2)
Thanks! could config it in application.properties, like spring.main.web-environment=falseMending
I found @EnableAutoConfiguration in a non-SpringBootApplication class, and had to add the exclude there too. TBH, I probably don't need @EnableAutoConfiguration there in the first place :/Ruvalcaba
S
67

This worked for me (1.3.0.M5) :

import org.springframework.boot.autoconfigure.jdbc.*;
import org.springframework.boot.autoconfigure.orm.jpa.*;

@Configuration
@EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class})
public class Application {

Exclude both classes.

It did not work with

@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class})
Stringency answered 12/10, 2015 at 15:46 Comment(1)
This one is for people who don't understand why they 'mysteriously' require database access in their application when they shouldn't(e.g when the database access is being handled by some other application and this one is just a 'client').Mita
W
38

You can add

spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration   

to your application.properties file.

Weigel answered 29/6, 2017 at 13:47 Comment(3)
This is especially useful when you have multiple profiles and one of them is in-memory.Franni
For me, I needed to exluse HibernateJpaAutoConfiguration also in order to work : spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration, org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfigurationMerryman
worked perfectly fine in my case, where i was launching from command lineContraindicate
P
20

Now that I look closer, I think that the DataSource problem is a red-herring. Boot's Hibernate auto-configuration is being triggered and that's what causing a DataSource to be required. Hibernate's on the classpath because you've got a dependency on spring-boot-starter-data-jpa which pulls in hibernate-entitymanager.

Update your spring-boot-starter-data-jpa dependency to exclude Hibernate:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-jpa</artifactId>
    <exclusions>
        <exclusion>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
        </exclusion>
    </exclusions>
</dependency>
Papandreou answered 6/6, 2014 at 16:58 Comment(10)
Error still the same :-(Katz
Are you sure you've applied the exclusion properly? mvn dependency:tree will help you to check. With the exclusion in place the DataSource problem's gone for me (I now see "Type demo.core.entity.Resource is not a known managed type", but that's a separate issue)Papandreou
Hi Andy does it mean you tested the actual project I posted? looks promisingKatz
Yes, that was with the project you posted. The only change I made was to add the Hibernate exclusion as described above.Papandreou
Cool, it seems what you've compiled was the master branch, or the JPA branch?Katz
and it seems 'mvn clean install' works fine, but did you try 'mvn appengine:devserver'?Katz
This red herring is a red herring. The answer's above, relating to the missing H2 dependency.Oruntha
Not in the OP's case. They were trying to use Datanucleus rather than HibernatePapandreou
after adding this i got entity manager factory could not be found because i have entity inside my class.Epicrisis
for a newer spring-boot-starter-data-jpa version, you need to exclude 'spring-boot-starter-jdbc'. This works for me.Archiphoneme
M
17

From the Spring manual.

Spring Boot can auto-configure embedded H2, HSQL, and Derby databases. You don’t need to provide any connection URLs, simply include a build dependency to the embedded database that you want to use.

For example, typical POM dependencies would be:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
    <groupId>org.hsqldb</groupId>
    <artifactId>hsqldb</artifactId>
    <scope>runtime</scope>
</dependency>

For me leaving out the spring-boot-starter-data-jpa dependency and just using the spring-boot-starter-jdbc dependency worked like a charm, as long as I had h2 (or hsqldb) included as dependencies.

Meadow answered 9/3, 2015 at 19:46 Comment(0)
S
9

Spring boot will look for datasoure properties in application.properties file.

Please define it in application.properties or yml file

application.properties

spring.datasource.url=xxx
spring.datasource.username=xxx
spring.datasource.password=xxx
spring.datasource.driver-class-name=xxx

If you need your own configuration you could set your own profile and use the datasource values while bean creation.

Saturninasaturnine answered 27/3, 2017 at 9:44 Comment(0)
A
7

I don't if it is too late to answer. I could solve this issue by excluding DataSourceAutoConfiguration from spring boot.

Anew answered 16/6, 2015 at 18:53 Comment(1)
Documentation on exluding found here: docs.spring.io/spring-boot/docs/current/reference/html/…Nairobi
F
5

I faced this exception while I was doing APIs for ElasticSearch using Spring Data. I did the following and it worked.

@SpringDataApplication(exclude = {DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class})
Ferule answered 20/4, 2017 at 6:15 Comment(0)
P
3

I solve my problem just adding @AutoConfigureTestDatabase(replace=Replace.NONE)

@RunWith(SpringRunner.class)
@DataJpaTest
@AutoConfigureTestDatabase(replace=Replace.NONE)
public class TestClienteRepository {

}
Petronel answered 6/8, 2016 at 15:46 Comment(0)
P
3

I had two dependencies with groupId of org.springframework.data, then I removed jpa and kept mongodb only , and it worked!

<dependency>
    <groupId>org.springframework.data</groupId>
    <artifactId>spring-data-mongodb</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.data</groupId>
    <artifactId>spring-data-jpa</artifactId>
</dependency>
Priapus answered 18/11, 2016 at 3:15 Comment(0)
C
3

I'd the similar problem and excluding the DataSourceAutoConfiguration and HibernateJpaAutoConfiguration solved the problem.

I have added these two lines in my application.properties file and it worked.

> spring.autoconfigure.exclude[0]=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
> spring.autoconfigure.exclude[1]=org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration
Commixture answered 10/1, 2019 at 16:20 Comment(1)
This worked for me as well. I've been fighting with a database connection issue with Java for an hour thanks @rajeev you made my dayGlobular
D
2

As this is one of the first topics returned in google for this error, I'll post what I did in case someone face the same issue.. I didn't want to exclude DataSourceAutoConfiguration neither use a memory database..

In my case I was setting the parameters as the other repliers said but the application.properties file was inside the wrong folder.. lol

So in case nothing like this works, check if the file is inside src/main/resources! In my case it was inside src/main/resources/static

Doreathadoreen answered 31/10, 2015 at 12:0 Comment(0)
H
2

I got the error message in the title from o.s.b.d.LoggingFailureAnalysisReporter along with the message "APPLICATION FAILED TO START". It turned out that I hadn't added -Dspring.profiles.active=dev to my Eclipse debug configuration so I had no active profile.

Halverson answered 25/5, 2017 at 21:20 Comment(1)
Exactly my problem as well. Adding the flag to the VM arguments of the debug configuration (Run -> Debug configurations... -> Maven build -> [build name] -> JRE -> VM arguments)Jujitsu
T
2

I too faced the same issue.

Cannot determine embedded database driver class for database type NONE.

In my case deleting the jar file from repository corresponding to the database fixes the issue. There was corrupted jar present in the repository which was causing the issue.

Turnbuckle answered 8/8, 2017 at 14:38 Comment(0)
D
2

Use this below dependency.

<dependency>
   <groupId>com.h2database</groupId>
   <artifactId>h2</artifactId>
   <scope>runtime</scope>
</dependency>
Dah answered 23/11, 2018 at 6:2 Comment(1)
I didn't need a database and was getting this error. I added this and it fixed it.Krum
M
1

In my case , I put it a maven dependency for org.jasig.cas in my pom that triggered a hibernate dependency and that caused Spring Boot to look for a datasource to auto-configure hibernate persistence. I solved it by adding the com.h2database maven dependency as suggested by user672009. Thanks guys!

Manny answered 7/1, 2015 at 8:8 Comment(0)
C
1

Doing below works.

@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})

But If I wanted to have dataSource, I should not do the above configuration. The below link says that we need to all the properties in application.properties file. All the properties should start with spring.datasource.*

http://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html

Cacogenics answered 22/9, 2015 at 15:30 Comment(0)
S
1

Answer is very simple, SpringBoot will look for Embeddable database driver, If you didn't configure in any of your configuration in form of XML or Annotations, it will throws this exception. Make the changes in your annotation like this

@EnableAutoConfiguration(exclude=DataSourceAutoConfiguration.class)
this will exclude the DataSourceAutoConfiguration. And the Perfect Simple Coding completion would be work if you have properly configured your class.

    @Controller
    @EnableAutoConfiguration(exclude=DataSourceAutoConfiguration.class)
     public class SimpleController {
      @RequestMapping("/")
      @ResponseBody
       String home() {
        return "Hello World!";
       }public static void main(String[] args) throws Exception {
        SpringApplication.run(SimpleController.class, args);
       }
    }
Sarabia answered 21/1, 2016 at 8:14 Comment(0)
B
1

If you really need "spring-boot-starter-data-jpa" as your project dependency and at the same time you don't want to allow your app to access any database, you can simply exclude auto-configuration classes

@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
Balling answered 20/9, 2017 at 12:21 Comment(0)
C
1

I tried all the mentioned things above but could not resolve the issue. I am using SQLite and my SQLite file was in the resources directory.

a) Set Up done for IDE

I need to manually add below lines in the .classpath file of my project.

<classpathentry kind="src" path="resources"/>
<classpathentry kind="output" path="target/classes"/>

After that, I refreshed and Cleaned the project from MenuBar at the top. like Project->Clean->My Project Name.

After that, I run the project and problem resolved.

application.properties for my project is

spring.datasource.url=jdbc:sqlite:resources/apiusers.sqlite
spring.datasource.driver-class-name=org.sqlite.JDBC
spring.jpa.properties.hibernate.dialect=com.enigmabridge.hibernate.dialect.SQLiteDialect
spring.datasource.username=
spring.datasource.password=
spring.jpa.hibernate.ddl-auto=update

b) Set Up done if Jar deployment throw same error

You need to add following lines to your pom.xml

  <build>
        <resources>
        <resource>
            <directory>resources</directory>
            <targetPath>${project.build.outputDirectory}</targetPath>
            <includes>
                <include>application.properties</include>
            </includes>
        </resource>
    </resources>
</build>

May be it may help someone.

Convertiplane answered 22/11, 2017 at 10:40 Comment(0)
I
1

if you do not have any database in your application simply disable the auto-config of datasource by adding below annotation.

@SpringBootApplication(exclude={DataSourceAutoConfiguration.class})
Isotone answered 7/2, 2018 at 11:48 Comment(0)
A
1

The same to @Anas. I can run it in Eclipse, but when i use "java -jar ..." run it, it giving me this error. Then i find my java build path is wrong, it missing the folder “src/main/resources”, so, the application can't find application.properties. When i add the “src/main/resources” folder in java build path, it worked.

And, you need add "@PropertySource({"application.properties"})" in your Application class.

Screenshot-1

Screenshot-2

Admissible answered 19/4, 2018 at 8:13 Comment(0)
R
1

This is how I resolved this problem.

In my case: I had to configure the datasource for MySQL Server, which was an external Server.

As we all know, Spring boot has capability to auto-configure DataSource for embedded databases.

Thus, I realized that I had to disable datasource auto-configuration in order use my custom configuration.

As mentioned above by many, I disabled Automatic DataSource configuration of Spring Boot at application.properties

spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration

I defined all hibernate configuration properties in a separate file: hibernate-mysql.properties

Then, I coded my own Custom Hibernate Configuration in following manner and it resolved the issue.

My way to configure the desired DataSource based on properties in a custom property file and populate your LocalSessionFactoryBean with your data source and other hibernate configuration.

Hibernate Custom Configuration Class:-
---------------------------------------------------------

Hibernate Custom Configuration

Radiomicrometer answered 5/6, 2018 at 9:4 Comment(0)
S
1

In my case, using IDEA, after remove the out direcory, then everything return to normal. I just don't know why, but it worked out.

Scrutiny answered 17/7, 2018 at 3:14 Comment(0)
W
1

Already enough of answers were posted. However, I'm posting what mistake i did and how i corrected it.

In my case, i had packaged my project as pom instead of jar

pom.xml:

...
 <packaging>pom</packaging>
...

Changed to:

...
 <packaging>jar</packaging>
...

It may helpful for someone with the same mistake.

Win answered 25/2, 2019 at 2:38 Comment(0)
S
0

You can download the derby-10.10.1.1.jar from the Maven Repository and place it in your WEB-INF/lib folder, like this Application/WEB-INF/lib/derby-10.10.1.1.jar. Your embedded AnnotationConfigEmbeddedWebApplicationContext will pickup the database driver and your webserver will start running without any issues :-)

Sarabia answered 21/1, 2016 at 10:26 Comment(0)
T
0

If you are using Gradle, include right jar of driver as below:

compile("org.mongodb:mongo-java-driver:3.3.0")

Or if using Maven then do it in Maven style, it should solve your problem.

Tetrachord answered 4/9, 2016 at 6:48 Comment(0)
C
0

To anybody coming to this thread after hours of banging your head against a wall. I solved this error by changing

create table `group`(
    id char(19) primary key
);

to

create table if not exists `group`(
    id char(19) primary key
);

in my schema.sql file in the resources directory.

Complication answered 21/9, 2016 at 2:52 Comment(0)
O
0

Right click the project and select the following option Maven -> Update Project. This has solved my issue.

Obola answered 24/4, 2018 at 5:49 Comment(0)
F
0

Generally, such error occurs when you've used JPA and forget to add database connection. So, you must add database related dependencies in your application.

Though, you want to use JPA without connecting any external database then add hsqldb in your dependency.

I hope this helps!

Favin answered 3/5, 2018 at 16:48 Comment(0)
N
0

My application file wasn't being read and Spring was trying to connect to an embedded H2 database (that wasn't added in the pom) instead. This was throwing the following error message:

if you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).

Make sure that your application file is being read by following this question.

Nitin answered 17/9, 2021 at 11:4 Comment(0)
N
0

If none of it works, try Making a Repository class as well as RepositoryInterface, though a class of implementation should automatically be generated by spring boot, this is what worked for me.

Number answered 25/11, 2021 at 8:38 Comment(0)
B
0

In my case i had an empty application.properties file at target\classes. I just deleted to fix the problem.

Boley answered 3/3, 2023 at 15:53 Comment(0)
R
-3

Delete C:\Users\admin\.IntelliJIdea2018.1\system\compile-server

Ritch answered 29/6, 2018 at 2:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.