问题描述
因此,尝试使用JPA实现运行第一个sprinboot应用程序,并收到以下错误:
So, trying to run first sprinboot application with JPA implementation and got the following error :
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,但这无济于事...
tried to add @Repositoy on my repo, and @EnableJpaRepositories to the main, but it doesn't helps...
存储库(没什么花哨的):
the repository (nothing too fancy):
@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'
}
有创意的人吗? :/
PS:忘记了application.properties
PS : forgot the 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
.
JPA will not get auto-configured without spring-boot-starter-data-jpa
as a dependency. With the dependency in place, you shouldn't even need @EnableJpaRepositories
.
此外,您可以删除spring-data-jpa
,因为spring-boot-starter-data-jpa
已经依赖于此.
Also, you may remove spring-data-jpa
as spring-boot-starter-data-jpa
already depends on that.
这篇关于找不到SpringBoot EntityManagerFactory的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!