找不到SpringBoot EntityManagerFactory

时间:2018-04-10 17:23:50

标签: spring-boot jpa gradle intellij-idea

因此,尝试使用JPA实现运行第一个sprinboot应用程序并收到以下错误:

Description:

Field personneDAO in com.example.demo.controller.PersonneController required a bean named 'entityManagerFactory' that could not be found.


Action:

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

尝试在我的repo上添加@Repositoy,并将@EnableJpaRepositories添加到main,但它没有帮助......

存储库(没什么太花哨的):

@Repository
public interface PersonneDAO extends JpaRepository<Personne, Integer>{
}

主要:

@SpringBootApplication
@EnableJpaRepositories(basePackages ="com.example.demo.repository")

public class DemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }
}

gradle依赖项:

dependencies {
    compile('org.springframework.boot:spring-boot-starter-web')
    providedRuntime('org.springframework.boot:spring-boot-starter-tomcat')
    testCompile('org.springframework.boot:spring-boot-starter-test')
    compile('org.apache.tomcat.embed:tomcat-embed-jasper')
    compile group: 'org.hibernate', name: 'hibernate-core', version: '5.2.16.Final'
    compile group: 'org.springframework.data', name: 'spring-data-jpa', version: '2.0.6.RELEASE'
    testCompile group: 'com.microsoft.sqlserver', name: 'mssql-jdbc', version: '6.5.1.jre9-preview'
}

任何想法的家伙? :/

PS:忘记了application.properties

spring.mvc.view.prefix = /WEB-INF/
spring.mvc.view.suffix = .jsp

spring.jpa.hibernate.ddl-auto=create
spring.datasource.url=jdbc:sqlserver://localhost/DB_TEST
spring.datasource.username=sa
spring.datasource.password=Pa$$w0rd
spring.datasource.driver-class-name=com.microsoft.sqlserver.jdbc.SQLServerDriver

1 个答案:

答案 0 :(得分:0)

如果没有spring-boot-starter-data-jpa作为依赖项,JPA将不会自动配置。有了依赖关系,你甚至不需要@EnableJpaRepositories

此外,您可以删除spring-data-jpaspring-boot-starter-data-jpa已取决于此。