spring-boot - 找不到SpringBoot EntityManagerFactory

标签 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.

试图在我的仓库上添加@Repositoy和@EnableJpaRepositories到主目录,但这没有帮助...

仓库(没什么花哨的):
@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

最佳答案

没有spring-boot-starter-data-jpa作为依赖项,JPA不会自动配置。有了相关性,您甚至不需要@EnableJpaRepositories

另外,您可以删除spring-data-jpa,因为spring-boot-starter-data-jpa已经依赖于此。

关于spring-boot - 找不到SpringBoot EntityManagerFactory,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49759623/

相关文章:

java - 使用hibernate处理大量数据

mysql - Spring Boot Data JPA - 如何获取特定id的数据

java - 如何使用注解代替 HttpSecurity?

java - JPA - JpaRepository 子记录具有父 ID 而不是实体记录,如果父记录已获取

java - "The filename or extension is too long error"使用渐变

java - Android Studio/Intellij,Gradle 错误 :Cause: peer not authenticated

gradle - 如何只包含来自main/java的特定文件作为jar的一部分,以使用gradle发布?

java - Controller 中的字段需要名为 'entityManagerFactory' 的 bean,但无法找到

java - Hibernate 无法执行 JDBC 批量更新

hibernate - Hibernate 3.5 中的 @OrderColumn 注释