Error creating bean with name 'entityManagerFactory' defined in class path resource
Good Night,
I have an application using Spring boot 1.5.10. I am trying to perform the connection with the oracle database, but I always have this error of the title.
Attempts:
- I have returned the Spring boot version (which stopped giving the error, but returned a blank json and in the console displayed as if doing the HQL query. But in this previous version gave several problems on port 8080);
- already removed and added O hibernate;
- I have already run mvn dependency: purge-local-repository + maven update;
- I've changed seats.
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
2
2 answers
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 your project and choose properties .
Click deployment Assembly .
Click add
Click Java Build Path Entries
Select Maven Dependencies
Click Finish .
At a glance here..
2
Author: LR10, 2018-02-06 11:26:08
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>
0
Author: danielso2007, 2018-02-06 11:41:17