因此,尝试使用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/