Ошибка при создании бина с именем 'requestMappingHandlerAdapter' исключение при добавлении зависимости Redis - PullRequest
0 голосов
/ 21 марта 2019

В моем приложении весенней загрузки я столкнулся с проблемой ниже.

Добавлена ​​зависимость ниже в файле build.gradle

compile('org.springframework.boot:spring-boot-starter-data-redis-reactive')

Добавлено в файл Application.java

@Bean
public ReactiveRedisConnectionFactory reactiveRedisConnectionFactory() {
    return new LettuceConnectionFactory("localhost", 6379);
}

@Bean
public ReactiveRedisTemplate<String, String> reactiveRedisTemplateString() {
    return new ReactiveRedisTemplate<>(reactiveRedisConnectionFactory(),
            RedisSerializationContext.string());
}

В классе обслуживания ApplicationService.java

@Autowired
ReactiveRedisTemplate<String, String> reactiveRedisTemplateString;

и я использую этот шаблон для добавления ключей и значений в Redis. При запуске сервера я получаю исключение ниже. Но если я добавлю строку ниже в классе Application.java, то это исключение не произойдет, но сопоставление запроса класса Controller не будет работать.

@EnableAutoConfiguration(exclude = { DataSourceAutoConfiguration.class,WebMvcAutoConfiguration.class })

Ошибка получения ниже

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'requestMappingHandlerAdapter' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter]: Factory method 'requestMappingHandlerAdapter' threw exception; nested exception is java.lang.NoSuchFieldError: defaultReader
    at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:625) ~[spring-beans-5.1.2.RELEASE.jar:5.1.2.RELEASE]
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:605) ~[spring-beans-5.1.2.RELEASE.jar:5.1.2.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1288) ~[spring-beans-5.1.2.RELEASE.jar:5.1.2.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1127) ~[spring-beans-5.1.2.RELEASE.jar:5.1.2.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:538) ~[spring-beans-5.1.2.RELEASE.jar:5.1.2.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:498) ~[spring-beans-5.1.2.RELEASE.jar:5.1.2.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) ~[spring-beans-5.1.2.RELEASE.jar:5.1.2.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.1.2.RELEASE.jar:5.1.2.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) ~[spring-beans-5.1.2.RELEASE.jar:5.1.2.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.1.2.RELEASE.jar:5.1.2.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:846) ~[spring-beans-5.1.2.RELEASE.jar:5.1.2.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:863) ~[spring-context-5.1.2.RELEASE.jar:5.1.2.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:546) ~[spring-context-5.1.2.RELEASE.jar:5.1.2.RELEASE]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) ~[spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775) [spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:316) [spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260) [spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248) [spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
    at com.falabella.turnero.TurneroApplication.main(TurneroApplication.java:68) [main/:na]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_131]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_131]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_131]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_131]
    at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) [spring-boot-devtools-2.1.0.RELEASE.jar:2.1.0.RELEASE]
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter]: Factory method 'requestMappingHandlerAdapter' threw exception; nested exception is java.lang.NoSuchFieldError: defaultReader
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) ~[spring-beans-5.1.2.RELEASE.jar:5.1.2.RELEASE]
    at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:620) ~[spring-beans-5.1.2.RELEASE.jar:5.1.2.RELEASE]
    ... 24 common frames omitted
Caused by: java.lang.NoSuchFieldError: defaultReader

Эта ошибка появляется только в моем проекте, я создам простой проект для вставки Redis, и он будет работать. Пожалуйста, помогите мне с проблемой.

Ниже приведен файл build.gradle

     buildscript {
        ext {
            springBootVersion = '2.1.0.RELEASE'
        }
        repositories {
            mavenCentral()
        }
        dependencies {
            classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
        }
    }
    plugins {
        id 'java'
    }
    plugins {
        id 'net.ltgt.apt' version '0.10'
    }



    apply plugin: 'java'
    apply plugin: 'idea'
    apply plugin: 'org.springframework.boot'
    apply plugin: 'io.spring.dependency-management'
    apply plugin: 'pmd'
    apply plugin: 'checkstyle'


    group 'my-services'
    version '0.1.0'

    sourceCompatibility = 1.8

    compileJava {
        sourceCompatibility = 1.8
        targetCompatibility = 1.8
    }

    repositories {
        mavenCentral()
    }

    tasks.withType(Checkstyle){
        reports{
            xml.enabled=true
            html.enabled=true
        }
    }

    tasks.withType(Pmd){
        reports{
            xml.enabled=true
            html.enabled=true
        }
    }
    pmd {
        pmdTest.enabled=true
        ruleSets = [
                'java-basic',
                'java-braces',
                'java-empty',
                'java-strings',
                'java-unnecessary'
        ]
    }

    dependencies {
        compile ('org.springframework.boot:spring-boot-starter-web:2.0.6.RELEASE')
        compile ('org.springframework.boot:spring-boot-starter-webflux:2.0.6.RELEASE')
        compile('org.springframework.boot:spring-boot-starter-actuator')
        compile "org.projectlombok:lombok:1.18.4"
        annotationProcessor 'org.projectlombok:lombok:1.18.4'
        compile ('com.google.firebase:firebase-admin:6.5.0')
        compile('io.micrometer:micrometer-registry-prometheus')
        compile ('io.springfox:springfox-swagger2:2.9.2')
        compile ('io.springfox:springfox-swagger-ui:2.9.2')
        compile('com.microsoft.azure:azure-eventgrid:1.2.0')
        compile group: 'com.microsoft.azure', name: 'azure-servicebus-spring-boot-starter', version: '2.0.7'
        compile group: 'org.springframework.retry', name: 'spring-retry', version: '1.2.2.RELEASE'
        compile group: 'org.springframework', name: 'spring-aop', version: '5.1.2.RELEASE'
        compile group: 'org.aspectj', name: 'aspectjweaver', version: '1.9.2'

        compile('org.springframework.boot:spring-boot-starter-data-redis')
        compile('org.apache.commons:commons-lang3:3.7')
        compile('commons-io:commons-io:2.6')
        runtime ('org.springframework.boot:spring-boot-devtools:2.0.6.RELEASE')
        testCompile ('org.springframework.boot:spring-boot-starter-test:2.0.6.RELEASE')
        testCompile ('junit:junit:4.12')
        testCompile ('com.squareup.okhttp3:mockwebserver:3.9.0')
    }

Ниже приведен обновленный файл build.gradle.

    buildscript {
    ext {
        springBootVersion = '2.1.0.RELEASE'
    }
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}
plugins {
    id 'java'
}
plugins {
    id 'net.ltgt.apt' version '0.10'
}



apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'pmd'
apply plugin: 'checkstyle'


group 'my-services'
version '0.1.0'

sourceCompatibility = 1.8

compileJava {
    sourceCompatibility = 1.8
    targetCompatibility = 1.8
}

repositories {
    mavenCentral()
}


tasks.withType(Checkstyle){
    reports{
        xml.enabled=true
        html.enabled=true
    }
}

tasks.withType(Pmd){
    reports{
        xml.enabled=true
        html.enabled=true
    }
}
pmd {
    pmdTest.enabled=true
    ruleSets = [
            'java-basic',
            'java-braces',
            'java-empty',
            'java-strings',
            'java-unnecessary'
    ]
}

dependencies {
    compile ('org.springframework.boot:spring-boot-starter-web')
    compile ('org.springframework.boot:spring-boot-starter-webflux')
    compile('org.springframework.boot:spring-boot-starter-actuator')
    compile "org.projectlombok:lombok:1.18.4"
    annotationProcessor 'org.projectlombok:lombok:1.18.4'
    compile ('com.google.firebase:firebase-admin:6.5.0')
    compile('io.micrometer:micrometer-registry-prometheus')
    compile ('io.springfox:springfox-swagger2:2.9.2')
    compile ('io.springfox:springfox-swagger-ui:2.9.2')
    compile('com.microsoft.azure:azure-eventgrid:1.2.0')
    compile group: 'com.microsoft.azure', name: 'azure-servicebus-spring-boot-starter', version: '2.0.7'
    //compile group: 'org.springframework', name: 'spring-aop', version: '5.1.2.RELEASE'
    //compile group: 'org.aspectj', name: 'aspectjweaver', version: '1.9.2'
    compile('org.springframework.boot:spring-boot-starter-aop')
    compile('org.springframework.retry:spring-retry')
    compile('org.springframework.boot:spring-boot-starter-data-redis')
    compile('org.apache.commons:commons-lang3:3.7')
    compile('commons-io:commons-io:2.6')
    runtime ('org.springframework.boot:spring-boot-devtools')
    testCompile ('org.springframework.boot:spring-boot-starter-test')
    testCompile ('junit:junit:4.12')
    testCompile ('com.squareup.okhttp3:mockwebserver:3.9.0')
}
...