0

In My spring boot application I am facing below problem.

Added below dependency in build.gradle file

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

Added in Application.java file

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

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

In service class ApplicationService.java

@Autowired
ReactiveRedisTemplate<String, String> reactiveRedisTemplateString;

and I am using this template to add keys and value to redis. While starting the server I am getting below exception.But if I add below line in Application.java class then this exception will not come,but Controller class request mapping will not work.

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

Getting below error

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

This error only coming in my project, I will create simple project for redis insertion then it will work. Please help me out with problem.

Below is the build.gradle file

     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')
    }

Below is the updated build.gradle file.

    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')
}
Rahul
  • 493
  • 3
  • 7
  • 25
  • These kind of issues generally arise due to mixing of jars of different versions of a framework or using incompatible versions. Please add your dependencies section of the `build.gradle` to your question. – M. Deinum Mar 21 '19 at 10:09
  • Hi @M.Deinum , Added build.gradle section. – Rahul Mar 21 '19 at 10:19
  • Remove the `spring-aop` and `junit` dependencies. The latter is part of `spring-boot-starter-test` to other is always included, but you could add `spring-boot-starter-aop`. Finally remove the version for `spring-retry` and `commons-lang3` as Spring Boot will properly manage those for you. The same for the explicit versions of the other `org.springframework.boot` dependencies, those are managed for you and you are currently mixing 2.1 and 2.0 jars which is trouble waiting to happen. – M. Deinum Mar 21 '19 at 10:24
  • followed above comment but still getting same error. – Rahul Mar 21 '19 at 10:59
  • Please add the updated version of your file. – M. Deinum Mar 21 '19 at 11:09
  • Added the updated version of build.gradle file, I did not changed spring-aop and azure-servicebus-spring-boot-starter dependency as it was giving fatal error. – Rahul Mar 21 '19 at 11:46
  • You have to remove `spring-aop` and `aspectj` and replace with `spring-boot-starter-aop` as mentioned in my comment. Currently you are mixing framework versions. Never do things like that. – M. Deinum Mar 21 '19 at 11:47
  • Removed above dependency and added spring-boot-starter-aop, but still getting the same issue. Updated the build.gradle file – Rahul Mar 21 '19 at 11:58
  • You are using Spring Boot 2.1 you probably also need an azure 2.1 version (Looking at the available versions they seem to follow the spring boot convention). You need a version that is compatible with your version of Spring Boot. As stated you are using incompatible libraries somewhere. You appear to be using Spring Boot 2.1.0.RELEASE but your stacktrace is 2.1.3.RELEASE. So something is changing that version. – M. Deinum Mar 21 '19 at 12:00
  • Stacktrace I have updated now, before I tried with 2.1.3 that is why it was showing 2.1.3 – Rahul Mar 21 '19 at 12:05
  • Why are you using both `web` and `webflux` in your project? You generally want one or the other but not both. – M. Deinum Mar 21 '19 at 12:28
  • As my project is reactive, I need to use webflux and if I remove web then I am getting java.lang.NoClassDefFoundError: org/springframework/web/servlet/HandlerMapping exception. – Rahul Mar 22 '19 at 07:15
  • No you don’t. You only need this id you use the reactive web part judging from the exception you aren’t using that. – M. Deinum Mar 22 '19 at 07:35
  • I did not get above comment @M.Deinum – Rahul Mar 22 '19 at 08:49
  • You don’t need webflux for the reactive redis, only if you use the reactive web stuff. Which judging from the fact something is requiring a HandletAdapter isn’t the case. – M. Deinum Mar 22 '19 at 12:14
  • I am using webFlux for other reactive web stuff that is why I can't remove any dependence. Removing one of the dependency is leading to other problems. – Rahul Mar 25 '19 at 06:43
  • Then you are doing things not correctlry and have dependencies on regular web classes. You cannot mix both in 1 application so you would have to fix those things first. – M. Deinum Mar 25 '19 at 06:56

0 Answers0