Невозможно определить в поле компонент, названный «entityManagerFactory», как использующий аннотацию автоматического подключения к репозиторию - PullRequest
2 голосов
/ 17 февраля 2020

Ошибка


Приложение не удалось запустить


Описание:

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)

Действие:

Подумайте об определении bean-компонента с именем entityManagerFactory в вашей конфигурации.


Код


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 
}
  • Я использую импорт Gradle
  • Зависимость JPA уже импортирована
@SpringBootApplication(scanBasePackages={"com.pvs.product", "com.pvs.pvscore"})
@EnableJpaRepositories

Обновление После удаления DataSourceAutoCondifguration it дал эту ошибку;

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 Ответ

1 голос
/ 17 февраля 2020

Пожалуйста, очистите файл gradle.build от зависимостей hibernate, spring-jdb c и spring-orm. Поскольку spring-boot-starter-jpa имеет спящий режим как транзитивную зависимость.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...