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\"
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.
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;
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
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")
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.
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.