Spring Data JPA - Consider defining a bean named 'entityManagerFactory' in your configuration

后端 未结 9 2177
一个人的身影
一个人的身影 2020-12-29 05:24

I am developing an application in Spring, using Tomcat, Mysql5, Java8... The problem is that I cannot deploy it, due to \"required bean \'entityManagerFactory\' not found\"

相关标签:
9条回答
  • 2020-12-29 05:37

    I had exact same issue. When I checked maven build log I have realised that there was an error about hibernate packages complaining about "invalid LOC header (bad signature)". I solved by deleting sub directories under .m2\repository\org\hibernate\hibernate-core and recompiling my project.

    0 讨论(0)
  • 2020-12-29 05:41

    You are missing repository configuration, as you have to configure it using @Repository,

    Following is incorrect,

    public interface UsuarioRepository  extends JpaRepository<Usuario, Long> {
    

    Rather it should be configured as repository as follows,

    @Repository
    public interface UsuarioRepository  extends JpaRepository<Usuario, Long> {
    

    This will make it a bean to be scanned and treat it as a repository and then your following code should work as expected as well,

    @Autowired
    private UsuarioRepository usuarioDao;
    
    0 讨论(0)
  • 2020-12-29 05:45

    Check persistence-api in pom file and try to change with hibernate-jpa-2.1 which is a part of spring-boot-started-data-jpa jar

    0 讨论(0)
  • 2020-12-29 05:47

    In your ClienteSpringApplication you only have the @SpringBootApplication annotation, wich is the equivalent of @Configuration, @EnableAutoConfiguration and @ComponentScan. What you are missing is the @EnableJpaRepositories annotation.

    package es.uc3m.tiw;
    
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    
    @SpringBootApplication
    @EnableJpaRepositories
    public class ClienteSpringApplication {
    
        public static void main(String[] args) {
            SpringApplication.run(ClienteSpringApplication.class, args);
        }
    }
    

    If it doesn't work like that try adding also the package of your repository:

    @EnableJpaRepositories("es.uc3m.tiw.dominios")
    
    0 讨论(0)
  • 2020-12-29 05:47

    In my case, i had wrong dependency: spring-data-jpa. when i changed to spring-boot-starter-data-jpa, it solved the problem. i didn't have to add any annotation @Repository nor @EnableJpa etc.

    0 讨论(0)
  • 2020-12-29 05:51

    In my case was the h2-1.4.193.jar, that contains the Driver class but it can't be read (very odd, may be is corrupted), as you can see: Driver class from h2-1.4.193

    So, you can update de spring-boot-starter-parent to 1.5.3.RELEASE (or newer) or override the managed version of your h2 dependency.

    0 讨论(0)
提交回复
热议问题