Parameter 0 of constructor in ..RoleService required a bean named 'entityManagerFactory' that could not be found

Viewed 1675

I'm trying to create a basic spring boot application and when I try to implement a repository i keep getting this error:

    Description:

    Parameter 0 of constructor in com.frana.taskme.services.RoleService required a bean named 'entityManagerFactory' that could not be found.

    Action:

    Consider defining a bean named 'entityManagerFactory' in your configuration.

I've used all kind of Annotations in the Application.java and all kind of properties and nothing changes.

This is my repository where you can find the app: https://github.com/franagibo/test

Is there some problem with the dependencies of the pom?

2 Answers

Update your pom.xml jpa dependency from:

<dependency>
    <groupId>org.springframework.data</groupId>
    <artifactId>spring-data-jpa</artifactId>
</dependency>

to

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>

Remove from application.propertiesspring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration

Dont forget to update the dependencies, you might need to clean m2/repository.

you are excluding the autoconfiguration on your application.properties

spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration

which means you have to manually define your DataSource, SessionFactory, EntityManager ...

Related