当前位置: 首页 > 知识库问答 >
问题:

无法将名为“Entity ManagerFactory”的bean字段标识为使用到存储库的自动连线注释

刘高峯
2023-03-14

错误

Field ProRepo in com.pvs.products.testservice.ProService required a bean named 'entityManagerFactory' that could not be found.

The injection point has the following annotations: @org.springframework.beans.factory.annotation.Autowired(required=true)

考虑在配置中定义一个名为'Entity ManagerFactory‘的bean。

Build.Gradle

plugins {
    id 'org.springframework.boot' version '2.1.12.RELEASE'
    id 'io.spring.dependency-management' version '1.0.8.RELEASE'
    id 'java'
    id 'war'
    id 'java-library'
    id "com.dorongold.task-tree" version "1.4"
}

group = 'com.pvs'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'

repositories {
    mavenCentral()
    jcenter()
}


dependencies {

    testCompile group: 'junit', name: 'junit', version: '4.12'
    compile 'io.springfox:springfox-swagger2:2.6.1'
    compile 'io.springfox:springfox-swagger-ui:2.6.1'
    implementation 'org.springframework.boot:spring-boot-starter-actuator'
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    implementation 'org.springframework.boot:spring-boot-starter-data-rest'
    implementation 'org.springframework.boot:spring-boot-starter-web'

    implementation "com.fasterxml.jackson.module:jackson-module-kotlin"
    implementation "org.jetbrains.kotlin:kotlin-reflect"
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
    implementation "com.okta.spring:okta-spring-boot-starter:1.2.1"
    implementation 'org.apache.cxf:cxf-rt-frontend-jaxrs:3.1.6'

    //Spring  Framework
//  implementation 'org.springframework.security:spring-security-config:4.2.8.RELEASE'
//  implementation 'org.springframework.security:spring-security-core:4.2.8.RELEASE'
//  implementation 'org.springframework.security:spring-security-web:4.2.8.RELEASE'
    implementation 'org.springframework:spring-core:5.1.5.RELEASE'

    testImplementation 'org.springframework.boot:spring-boot-starter-test'
    testImplementation 'org.springframework.amqp:spring-rabbit-test'
//  testImplementation 'org.springframework.security:spring-security-test'

    compile group: 'org.springframework', name: 'spring-core', version: '5.1.5.RELEASE'
    implementation 'org.springframework:spring-jdbc:4.3.20.RELEASE'
    implementation 'org.springframework:spring-orm:4.3.20.RELEASE'
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    implementation 'org.springframework.boot:spring-boot-starter-data-rest'
    implementation 'org.springframework.boot:spring-boot-starter-data-solr'
//  implementation 'org.springframework.boot:spring-boot-starter-jdbc'
    implementation 'org.springframework.boot:spring-boot-starter-oauth2-client'

//  implementation 'org.springframework.boot:spring-boot-starter-security'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    // https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-actuator
    compile group: 'org.springframework.boot', name: 'spring-boot-starter-actuator'



    implementation 'org.springframework.boot:spring-boot-starter-web'
//  compile group: 'org.springframework.boot', name: 'spring-boot-autoconfigure', version: '2.1.2.RELEASE'
    compile 'org.mariadb.jdbc:mariadb-java-client:1.5.7'
    compile 'org.springframework.boot:spring-boot-starter-data-redis'


    implementation 'com.h2database:h2'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
//  compile group: 'org.springframework.security.oauth', name: 'spring-security-oauth2', version: '2.2.1.RELEASE'

    //JDBC
//  implementation 'org.springframework.boot:spring-boot-starter-jdbc'
//  implementation 'org.springframework.session:spring-session-jdbc'
    implementation 'org.springframework:spring-jdbc:4.3.20.RELEASE'

    //Hibernate
    implementation 'org.hibernate:hibernate-core:5.2.12.Final'
    implementation 'org.hibernate:hibernate-ehcache:5.2.12.Final'

    testCompile 'org.hibernate:hibernate-ehcache:5.2.12.Final'
    compile 'org.apache.commons:commons-lang3:3.1'

    implementation 'org.apache.lucene:lucene-core:6.3.0'
    implementation 'org.apache.solr:solr-core:6.3.0'
    implementation 'org.apache.solr:solr-solrj:6.3.0'
    implementation 'org.apache.solr:solr-velocity:6.3.0'



    implementation 'com.zaxxer:HikariCP:3.2.0'

    compile (group: 'org.apache.solr', name: 'solr-velocity', version: '6.3.0') {
        exclude group: 'org.slf4j', module: 'jcl-over-slf4j'
    }


    compile group: 'org.bytedeco', name: 'javacv-platform', version: '1.5.2'

    //XML and JSON
    implementation 'com.fasterxml.jackson.datatype:jackson-datatype-hibernate5'

    //Java org
    implementation 'net.sf.jpf:jpf-boot:1.5'
    implementation 'net.sf.jpf:jpf:1.5'
    implementation 'com.ibm.icu:icu4j:3.8'

    //MySQL
    implementation 'org.hsqldb:hsqldb:2.2.8'
    implementation 'org.hsqldb:sqltool:2.2.8'

    //Hibernate
    //compile 'org.hibernate:hibernate-c3p0:4.1.9.Final'
    compile 'org.hibernate:hibernate-ehcache:4.1.9.Final'

    //Lombok
    compileOnly 'org.projectlombok:lombok'
    annotationProcessor 'org.projectlombok:lombok'


    //    newly added
    compile group: 'org.hibernate', name: 'hibernate-entitymanager', version: '5.4.12.Final'
    compile group: 'javax.xml.bind', name: 'jaxb-api', version: '2.1'
    compile group: 'org.springframework.data', name: 'spring-data-redis', version: '2.1.12.RELEASE'
//  //commented above librabry with old version
//  compile group: 'org.springframework.boot', name: 'spring-boot-autoconfigure'
//  compile group: 'org.springframework.boot', name: 'spring-boot-starter-parent', version: '2.2.4.RELEASE', ext: 'pom'

}

application.yml

spring:
  main:
    allow-bean-definition-overriding: true
  security:
    username: abc
    password: abc

  datasource:
    driverClassName: org.mariadb.jdbc.Driver
     url: jdbc:mariadb:failover://192.168.100.101:3306/tentDB?autoReconnect=true

    username: root
    password: roor

    timeBetweenEvictionRunsMillis: 1000
    testWhileIdle: true
    validationQuery: SELECT 1
  jpa:
    hibernate.ddl-auto: update
    generate-ddl: true
    show-sql: true

logging:
  level:
    org:
      springframework:
        security: DEBUG

endpoints:
  info:
    enabled: true
    id: information
    sensitive: false

management:
  security:
    enabled: true
  endpoints:
    shutdown:
      enabled: true
      enabled-by-default: false
      info:
        enabled: true
    web:
      base-path: /
      exposure:
        include: *

@Entity
@Table(name = "pv_product")
public class product{
//properties are defined inside
}
@Repository
public interface ProRepo extends JpaRepository<pv_product, BigInteger> {
    @Override
    List<pv_product> findAll();
}
@Component
public class ProService {
    @Autowired
    ProRepo proRepo;
//methods are implemented 
}
    null
@SpringBootApplication(scanBasePackages={"com.pvs.product", "com.pvs.pvscore"})
@EnableJpaRepositories

删除DataSourceAutoConditfGuration后Update出现此错误;

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Unsatisfied dependency expressed through method 'entityManagerFactory' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'entityManagerFactoryBuilder' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Unsatisfied dependency expressed through method 'entityManagerFactoryBuilder' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jpaVendorAdapter' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.orm.jpa.JpaVendorAdapter]: Factory method 'jpaVendorAdapter' threw exception; nested exception is java.lang.NoSuchFieldError: HANA

共有1个答案

越姚石
2023-03-14

请从hibernate依赖关系、spring-jdbc和spring-orm中清除您的gradle.build文件。由于spring-boot-starter-jpa具有hibernate作为可传递依赖项。

 类似资料:
  • Hy各位 我有我的麻烦的简化版本。我正在尝试运行我的应用程序,但它失败了,因为存储库不能被注入。我已经尝试将存储库注释为服务,并添加要扫描的存储库包,但都没有效果。有人能帮我吗? 我有个例外 描述: br中的字段topicRepository。通用域名格式。阿鲁拉。控制器。TopicController需要类型为“br”的bean。通用域名格式。阿鲁拉。存储库。找不到TopicRepository

  • 我与SpringBoot和JPA合作。我收到一个无法完成的错误。 这是我的主要课程: 这是我的班级失败的原因: 这是类: 这是错误消息: 错误创建bean的名称'请求LoggerImpl':注入自动生成的依赖失败; 无法自动关联字段:专用com。存储库。请求logdao.com。记录器。impl。RequestLoggerImpl。请求logdao;嵌套的异常是org。springframewor

  • 我正在为我的应用程序使用模拟存储库 以下是服务的外观片段: 以下是存储库代码: 当我使用执行main()时,它工作正常。 但是,当我想运行测试类: 它会因以下stacktrace而失败: 原因:org。springframework。豆。工厂NoSuchBean定义异常:没有类型为“edu”的合格bean。勒勒亚克。存储库。WeatherStationRepositoryMock’可用:至少需要1

  • 被异常卡住,下面是日志: org.springframework.beans.factory.BeanCreation异常:创建名为扬声器的bean时出错:注入自动生成的依赖项失败;嵌套异常是org.springframework.beans.factory.BeanCreation异常:无法自动连接方法:公共最终无效org.mybatis.spring.support.SqlSessionDao

  • 在我们的代码中,我们有许多Spring JPA存储库,每个模型类一个。它们被定义为(其中

  • 我在Spring+SpringMVC+Hibernate+MySQL web应用程序中的Spring配置有一个问题。Spring无法创建我在Service类中宣布的bean。 下面是Controller类 应用程序-上下文 最后是我的StackTrace 原因:org.SpringFramework.Beans.Factory.BeanCreationException:无法自动连接字段:priv