Error creating bean with name 'entityManagerFactory' defined in class path resource

1

Good evening,

I have an application using Spring boot 1.5.10. I am trying to connect to the oracle database, but I always have the title error.

Attempts:

  • I have already returned the version of spring boot (which stopped giving the error, but returned a blank json and on the console it appeared as if it were doing the HQL query, but in that previous version it gave several problems in port 8080) li>
  • I have already taken and added hibernate;
  • I have run mvn dependency: purge-local-repository + maven update;
  • I've already changed my bank.

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>

message in the console

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
    
asked by anonymous 06.02.2018 / 03:56

2 answers

2

Adds the javassist dependency:

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

You need to add the " Maven dependency".

Right click on your project and choose Properties .

click Deployment Assembly .

click add

click Java Build Path Entries

Select Maven Dependencies

click Finish .

Take a look here ..

How to use MySql in Java EE?

    
06.02.2018 / 12:26
0

Test using 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>
    
06.02.2018 / 12:41