0
votes

I'm doing simple api with Spring Boot and embeeded database and it's hits me an

NoClassDefFoundError. : Error creating bean with name 'entityManagerFactory'

Maybe you know which dependency I should include to my pom.xml. Maven project. here is what i have:

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

    <dependency>
        <groupId>org.apache.derby</groupId>
        <artifactId>derby</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Unsatisfied dependency expressed through method 'entityManagerFactory' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'entityManagerFactoryBuilder' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Unsatisfied dependency expressed through method 'entityManagerFactoryBuilder' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jpaVendorAdapter' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.orm.jpa.JpaVendorAdapter]: Factory method 'jpaVendorAdapter' threw exception; nested exception is java.lang.NoClassDefFoundError:

2
NoClassDefFoundError has javadocs. docs.oracle.com/javase/7/docs/api/java/lang/… a class or a dependency of that class is not in the CLASSPATH. Nothing (explicitly) to do with the JPA or anything, just basic Javauser8558216

2 Answers

1
votes

hibernate-core and hibernate-entitymanager are being transitively included via spring-boot-starter-data-jpa

Edited: Could you first try removing you local .m2/repository? Sometime it gets corrupted.

rm -rf ~/.m2/repository

Could you include which Spring Boot version are you using pom.xml content.

Could you also include you data source and JPA properties?

0
votes

1) Make sure none of your dependencies (except spring-boot-starter-data-jpa) have inclusive dependency to hibernate-core. Otherwise libraries may get clashed.

2) You may also need to add this artifact:

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-entitymanager</artifactId>
</dependency>

Version should be inferred.