Error Creating bean with name 'entityManagerFactory' defined in class path Resource

Asked

Viewed 12,692 times

2

Good night,

I have an application using Spring boot 1.5.10. I’m trying to make the connection to the oracle database, but I always have this title error.

Attempts:

  • I went back to the spring boot version (which stopped giving the error, but returned a blank json and displayed on the console as if making the HQL query. But in this previous version gave several problems at door 8080);
  • I already took and added Hibernate;
  • I already ran mvn dependency:purge-local-Repository + Maven update;
  • I’ve already changed banks.

Model

import java.util.Date;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;

@Entity
public class Tconta {

@Id
@GeneratedValue
private Long codigo;
private Double valor;
(...)   

public Long getCodigo() {
    return codigo;
}
public void setCodigo(Long codigo) {
    this.codigo = codigo;
(...)

Controller

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import br.com.academia.model.Tconta;
import br.com.academia.repository.Contas;

@RestController
@RequestMapping("/contas")
public class ContaController {

@Autowired
private Contas ContasRepository;

@RequestMapping(method = RequestMethod.GET)
public ResponseEntity<List<Tconta>> show()
{
       return new ResponseEntity<List<Tconta>>(ContasRepository.findAll(), 
   HttpStatus.OK);
  }
}

Repository

package br.com.academia.repository;

import org.springframework.data.jpa.repository.JpaRepository;

import br.com.academia.model.Tconta;

public interface Contas extends JpaRepository<Tconta, Long>{

//public Tconta findByCode(int codigo);
}

POM

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.10.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>
</properties>

<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.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.17</version>
    </dependency>
    <!--Ja testei com e sem a hibernate-entitymanager-->
      <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <version>5.0.3.Final</version>
    </dependency>
</dependencies>

console message

Error starting ApplicationContext. To display the auto-configuration report 
re-run your application with 'debug' enabled.
2018-02-06 00:26:24.649 ERROR 7104 --- [           main] 
o.s.boot.SpringApplication               : Application startup failed

org.springframework.beans.factory.BeanCreationException: Error creating bean 
with name 'entityManagerFactory' defined in class path resource [org/ 
springframework/ boot/ autoconfigure/ orm /jpa / 
HibernateJpaAutoConfiguration.cl
ass]: Invocation of init method failed; nested exception is 
java.lang.NoClassDefFoundError: javassist/bytecode/ClassFile
at 
org.springframework. beans. factory. support. 
AbstractAutowireCapableBeanFactory.initializeBean ( 
AbstractAutowireCapableBeanFactory.java:1628 )  ~[ spring-beans-
4.3.14.RELEASE.jar:4.3.14.RELEASE]
at (...)
Caused by: java.lang.NoClassDefFoundError: javassist/bytecode/ClassFile
  • I tried to fix this error by changing dependencies but it didn’t work until I realized that my datasource was not being correctly assigned to my database. So try checking your application.properties or applicationcontext.xml, in my case the url was wrong -> https://stackoverflow.com/questions/34741443/hikaricp-postgresql-driver-claims-to-not-accept-jdbc-url

2 answers

2


Add the javassist dependency:

<dependency>
    <groupId>org.javassist</groupId>
    <artifactId>javassist</artifactId>
    <version>3.20.0-GA</version>
</dependency>

You need to add to "Dependency Maven".

right click on your project and choose estates.

click on Deployment Assembly.

click on add

click on Java Build Path Entries

select Maven Dependencies

click on Finish.

Take a look here..

How to use Mysql in Java EE?

  • Master, thank you very much! The error stopped popping on the console with this dependency. But it still returns an empty Json even running the HQL query. On the console appears: Hibernate: select tconta0_.codigo as codigo1_0_, tconta0_.juros as juros2_0_.... I had tested with data in memory and render without errors.

  • you tested on some tool ? such as Postman !!

  • Yes, I’m using Postman. I tested tbm by browser already q is a get, + gave in msm. Returns a [].

  • have to see what happened.

0

Test use the following dependencies:

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

Also use:

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-entitymanager</artifactId>
    <version>5.2.3.Final</version>
</dependency>
  • Master, I managed to insert the javassist dependency. Thank you very much!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.