【发布时间】:2019-05-25 20:05:37
【问题描述】:
请告诉我如何克服它。 我在构建时使用 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 {
}
好像做了功课,但是不能建项目。 很久没解决这个问题,也许有人知道解决办法。
【问题讨论】:
-
你确定上面的编译了吗?我没有使用 gradle,但我没有看到 spring-data-jpa 的依赖项。
-
你有
compile group: 'org.springframework.data', name: 'spring-data-jpa', version: '2.0.6.RELEASE'
标签: spring spring-boot gradle spring-data-jpa