0

I'm creating Java app using Spring Boot. My app fails to start. Here's the error I get:

2017-08-31 15:44:23.246  WARN 12484 --- [           main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt:  org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Dbcp2.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.commons.dbcp2.BasicDataSource]: 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-08-31 15:44:23.249  INFO 12484 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2017-08-31 15:44:23.262  WARN 12484 --- [ost-startStop-1] o.a.c.loader.WebappClassLoaderBase       : The web application [ROOT] appears to have started a thread named [Abandoned connection cleanup thread] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
 java.lang.Object.wait(Native Method)
 java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:143)
  com.mysql.cj.jdbc.AbandonedConnectionCleanupThread.run(AbandonedConnectionCleanupThread.java:43)
 2017-08-31 15:44:23.288  INFO 12484 --- [           main] utoConfigurationReportLoggingInitializer : 

Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2017-08-31 15:44:23.294 ERROR 12484 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
APPLICATION FAILED TO START
***************************

Description:

Cannot determine embedded database driver class for database type NONE

Action:

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).

As I understand here is described the solution: Why must the JDBC driver be put in TOMCAT_HOME/lib folder?

But! I have all the files in WEB-INF/lib. There's no Tomcat path at all. All .jar files are in the same WEB-INF/lib. Could anyone explain what exactly should be done?

Here's my .POM file below:

 <?xml version="1.0" encoding="UTF-8"?>
 <project xmlns="http://maven.apache.org/POM/4.0.0"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0  http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<packaging>war</packaging>
<groupId>com.boris</groupId>
<artifactId>movie-project</artifactId>
<version>1.0-SNAPSHOT</version>

<build>

<plugins>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
            <source>1.6</source>
            <target>1.6</target>
        </configuration>
    </plugin>
</plugins>
</build>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.6.RELEASE</version>
</parent>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>  
</dependency>

<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.6.2</version>
</dependency>

<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.5</version>
</dependency>

<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>6.0.5</version>
</dependency>


<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4.7</version>
</dependency>

<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>commons-net</groupId>
<artifactId>commons-net</artifactId>
<version>3.6</version>
</dependency>

<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.2.9.Final</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>4.3.7.RELEASE</version>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-dbcp2</artifactId>
<version>2.1.1</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.3.7.RELEASE</version>
</dependency>

</dependencies>

    </project>

Many thanks for your help!

Boris
  • 404
  • 1
  • 7
  • 20
  • Can you share your application properties, please? It could be helpful. – Z. Clément Aug 31 '17 at 19:17
  • I used the same properties files and dependencies that I used in my previous project that worked. This is what I have in my application.properties file: spring.mvc.view.prefix: / spring.mvc.view.suffix: .jsp server.port=8181 # MySQL properties db.driver=com.mysql.cj.jdbc.Driver db.url=jdbc:mysql://localhost:3306/movies?useUnicode=true&useSSL=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC db.username=**** db.password=**** # Hibernate properties hibernate.show_sql=true hibernate.hbm2ddl.auto=update – Boris Sep 01 '17 at 04:06

3 Answers3

0

Generally speaking, with applications serves, one has to watch out for the various class loaders. If you have configured the JDBC resource in a level above the application one, then the driver should also be available for the class loader above the application level one.

0

Given that you have not specified any datasource Spring Boot will try to load either H2 or Derby if you have any of those on the classpath.

Given that you want to use mysql, you should probably add a jdbc url in application.properties..

There is more in the reference guide under 'Working with SQL data'

https://docs.spring.io/spring-boot/docs/1.5.6.RELEASE/reference/htmlsingle/#boot-features-sql

Niels Bech Nielsen
  • 4,777
  • 1
  • 21
  • 44
  • BTW, the leaking is done from mysql-connector-j. Not to worry if you run a boot app from CLI. However, if deploying on tomcat, you should probably install it in the container directly anyway. – Niels Bech Nielsen Sep 01 '17 at 10:05
0

Thanks everyone for your help. But the problem was much more simple than I supposed. dbService class didn't get it's properties because it didn't see my AppConfig class. Using @ComponentScan solved this.

Boris
  • 404
  • 1
  • 7
  • 20