首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Spring JPA - entitymanagerfactory找不到,为什么?

Spring JPA - entitymanagerfactory找不到,为什么?
EN

Stack Overflow用户
提问于 2018-12-28 05:26:37
回答 1查看 410关注 0票数 0

请告诉我如何克服它。当我在构建时使用Gradle时,我得到一个错误:

代码语言:javascript
运行
复制
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.

应用程序文件:

代码语言:javascript
运行
复制
@EnableJpaRepositories("com.test.api.repository")
@SpringBootApplication
public class ApiApplication {

    public static void main(String[] args) {
        SpringApplication.run(ApiApplication.class, args);
    }
}

application.properties

代码语言:javascript
运行
复制
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

代码语言:javascript
运行
复制
buildscript {
    ext {
        springBootVersion = '2.1.0.RELEASE'
    }
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}

模型

代码语言:javascript
运行
复制
@Entity
@Table(name = "user")
@EntityListeners(AuditingEntityListener.class)
@JsonIgnoreProperties(value = {"createdAt", "updatedAt"},
        allowGetters = true)
public class User implements Serializable {
}

它似乎是在做功课,但却无法构建一个项目。很长一段时间我都不能解决这个问题,也许有人知道解决方案。

EN

回答 1

Stack Overflow用户

发布于 2018-12-28 12:51:23

如果排除DataSourceAutoConfiguration类,则必须手动设置DataSource bean。

代码语言:javascript
运行
复制
spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53951045

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档