1

I recently decide add spring-boot to a existing spring project which uses hibernate configured by java code. I have this pom.xml file:

<?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>

    <groupId>com.spring</groupId>
    <artifactId>app</artifactId>
    <version>0.1.0</version>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.1.8.RELEASE</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.security</groupId>
            <artifactId>spring-security-web</artifactId>
            </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-config</artifactId>
            </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-taglibs</artifactId>
            </dependency>
        <dependency>
           <groupId>org.hibernate</groupId>
           <artifactId>hibernate-core</artifactId>
           <version>4.3.6.Final</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-orm</artifactId>
            </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-tx</artifactId>
            </dependency>
    </dependencies>

    <properties>
        <start-class>com.spring.app.Application</start-class>
    </properties>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

When I try run the applications (after the commands: mvn compile / mvn package / java -jar ), I get this error:

Caused by: java.lang.ClassNotFoundException: org.apache.tomcat.dbcp.dbcp.BasicDataSource
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at org.springframework.boot.loader.LaunchedURLClassLoader.doLoadClass(LaunchedURLClassLoader.java:168)
    at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:134)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    ... 136 common frames omitted

anyone can tell me what I am missing here?

Kleber Mota
  • 8,521
  • 31
  • 94
  • 188
  • Can you post your configuration? I suspect you are configuring your own datasource, something that Spring Boot can do for you by just adding a couple of properties to an `application.properties` file. – M. Deinum Oct 24 '14 at 13:09

2 Answers2

1

You are missing data source dependency. You can resolve it by either adding DBCP dependency or you can replace your spring-tx, spring-orm and hibernate-core dependencies with spring-boot-starter-data-jpa and you should have all the persistence dependencies you need in your Spring Boot project:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
Bohuslav Burghardt
  • 33,626
  • 7
  • 114
  • 109
  • 1
    Ok, I replace my spring-tx, spring-orm and hibernate-core entries by this spring-boot-starter-data-jpa, but don't solve the problem. In my previous projects, to use this BasicDataSource class, I needed add the apache tomcat to my build path. Seems the embed tomcat container from spring-boot don't have this class? – Kleber Mota Oct 24 '14 at 12:45
  • 1
    Newer tomcat versions have the tomcat-jdbc as their DataSource implementation and not commons-dbcp anymore. Judging from the stacktrace you have configured the datasource explicitly yourself instead of letting Spring Boot configure one for you. It would suggest the latter and remove the commons-dbcp dependency which will let you use the tomcat-jdbc datasource which is faster then commons-dbcp. – M. Deinum Oct 24 '14 at 13:06
0

Following the two answers posted here (one was deleted), I add this two dependencies to my pom.xml:

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
        <groupId>commons-dbcp</groupId>
        <artifactId>commons-dbcp</artifactId>
    </dependency>

and remove this three:

   <dependency>
       <groupId>org.hibernate</groupId>
       <artifactId>hibernate-core</artifactId>
       <version>4.3.6.Final</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-orm</artifactId>
        </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-tx</artifactId>
        </dependency>

and this solve the problem.

Kleber Mota
  • 8,521
  • 31
  • 94
  • 188