请告诉我如何克服它。
我在构建时使用Gradle时遇到错误:
Description:
Field userRepository in com.fitness.api.controller.UserController required a bean named 'entityManagerFactory' that could not be found.
Action:
Consider defining a bean named 'entityManagerFactory' in your configuration.
申请文件:
@EnableJpaRepositories("com.test.api.repository")
@SpringBootApplication
public class ApiApplication {
public static void main(String[] args) {
SpringApplication.run(ApiApplication.class, args);
}
}
application.properties
spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
## Spring DATASOURCE (DataSourceAutoConfiguration & DataSourceProperties)
# MySQL properties
spring.datasource.url = jdbc:mysql://localhost:3306/test?useSSL=false
spring.datasource.username = root
spring.datasource.password = 1234
## Hibernate Properties
# The SQL dialect makes Hibernate generate better SQL for the chosen database
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5InnoDBDialect
# Hibernate ddl auto (create, create-drop, validate, update)
spring.jpa.hibernate.ddl-auto = update
build.gradle
buildscript {
ext {
springBootVersion = '2.1.0.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
模型
@Entity
@Table(name = "user")
@EntityListeners(AuditingEntityListener.class)
@JsonIgnoreProperties(value = {"createdAt", "updatedAt"},
allowGetters = true)
public class User implements Serializable {
}
它似乎在上课,但无法构建项目。
很长一段时间我无法解决这个问题,也许有人知道解决方案。
最佳答案
如果排除DataSourceAutoConfiguration
类,则必须手动设置DataSource
bean。
spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
关于spring - Spring JPA-找不到实体管理工厂,为什么?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/53951045/