代码之家  ›  专栏  ›  技术社区  ›  j0w

未找到SpringBoot EntityManagerFactory

  •  0
  • j0w  · 技术社区  · 7 年前

    因此,尝试使用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,并在main中添加@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);
        }
    }
    

    渐变依赖项:

    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'
    }
    

    有什么想法吗,伙计们/

    附言:忘记申请了。属性

    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 回复  |  直到 7 年前
        1
  •  0
  •   crizzis    7 年前

    没有 spring-boot-starter-data-jpa 作为依赖项。有了依赖关系,您甚至不需要 @EnableJpaRepositories

    此外,您可以删除 spring-data-jpa spring boot starter数据jpa 已经取决于这一点了。