2

I am working on a Spring Boot REST application. However, whenever I attempt to start it I receive the following error:

Error creating bean with name 'requestMappingHandlerAdapter' defined in class path resource [org/springframework/boot/autoconfigure/web/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

Now, from this question (and the stack), I gather it is an issue with JsonSmart and/or JsonPath as used by Jackson for conversion.

Caused by: java.lang.NoSuchFieldError: defaultReader
at com.jayway.jsonpath.spi.json.JsonSmartJsonProvider.<init>(JsonSmartJsonProvider.java:39) ~[json-path-2.2.0.jar:2.2.0]
at com.jayway.jsonpath.internal.DefaultsImpl.jsonProvider(DefaultsImpl.java:21) ~[json-path-2.2.0.jar:2.2.0]
at com.jayway.jsonpath.Configuration$ConfigurationBuilder.build(Configuration.java:231) ~[json-path-2.2.0.jar:2.2.0]
at org.springframework.data.web.JsonProjectingMethodInterceptorFactory.<init>(JsonProjectingMethodInterceptorFactory.java:72) ~[spring-data-commons-1.13.9.RELEASE.jar:na]
at org.springframework.data.web.ProjectingJackson2HttpMessageConverter.initProjectionFactory(ProjectingJackson2HttpMessageConverter.java:85) ~[spring-data-commons-1.13.9.RELEASE.jar:na]
at org.springframework.data.web.ProjectingJackson2HttpMessageConverter.<init>(ProjectingJackson2HttpMessageConverter.java:70) ~[spring-data-commons-1.13.9.RELEASE.jar:na]
at org.springframework.data.web.config.SpringDataWebConfiguration.extendMessageConverters(SpringDataWebConfiguration.java:129) ~[spring-data-commons-1.13.9.RELEASE.jar:na]
at org.springframework.web.servlet.config.annotation.WebMvcConfigurerComposite.extendMessageConverters(WebMvcConfigurerComposite.java:143) ~[spring-webmvc-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration.extendMessageConverters(DelegatingWebMvcConfiguration.java:122) ~[spring-webmvc-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport.getMessageConverters(WebMvcConfigurationSupport.java:722) ~[spring-webmvc-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport.requestMappingHandlerAdapter(WebMvcConfigurationSupport.java:529) ~[spring-webmvc-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$EnableWebMvcConfiguration.requestMappingHandlerAdapter(WebMvcAutoConfiguration.java:384) ~[spring-boot-autoconfigure-1.5.9.RELEASE.jar:1.5.9.RELEASE]
at org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$EnableWebMvcConfiguration$$EnhancerBySpringCGLIB$$f44b477f.CGLIB$requestMappingHandlerAdapter$7(<generated>) ~[spring-boot-autoconfigure-1.5.9.RELEASE.jar:1.5.9.RELEASE]
at org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$EnableWebMvcConfiguration$$EnhancerBySpringCGLIB$$f44b477f$$FastClassBySpringCGLIB$$d3f16523.invoke(<generated>) ~[spring-boot-autoconfigure-1.5.9.RELEASE.jar:1.5.9.RELEASE]
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) ~[spring-core-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:358) ~[spring-context-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$EnableWebMvcConfiguration$$EnhancerBySpringCGLIB$$f44b477f.requestMappingHandlerAdapter(<generated>) ~[spring-boot-autoconfigure-1.5.9.RELEASE.jar:1.5.9.RELEASE]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_40]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_40]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_40]
at java.lang.reflect.Method.invoke(Method.java:497) ~[na:1.8.0_40]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]
... 19 common frames omitted

I presume it may be some sort of dependency issue; however, I have made attempts at switching versions and manually bringing in dependencies (such as Spring Data) to override the starter defaults. No success. Here is my gradle file:

  buildscript {
    ext {
        springBootVersion = '1.5.9.RELEASE'
    }
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'

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

repositories {
    mavenCentral()
}


dependencies {
testCompile('junit:junit:4.11')
    testCompile('org.springframework.boot:spring-boot-starter-test')
    compile('org.springframework.boot:spring-boot-starter-data-jpa')
    compile('org.springframework.boot:spring-boot-starter-web')
    compile('org.springframework.boot:spring-boot-starter-data-rest')
    compile('org.springframework.boot:spring-boot-starter-security')
    compile('org.springframework.security.oauth:spring-security-oauth2:2.2.1.RELEASE')
        compile('org.springframework.security:spring-security-jwt:1.0.9.RELEASE')
compile('org.modelmapper:modelmapper:0.7.5')
    compile('org.hibernate:hibernate-java8:5.0.0.Final')
compile('com.microsoft.sqlserver:mssql-jdbc:6.1.0.jre8')



}

Any advice is appreciated. Thanks.

KellyM
  • 2,472
  • 6
  • 46
  • 90
  • 2
    Have you checked [this](https://stackoverflow.com/questions/40954331/json-parser-java-lang-nosuchfielderror-defaultreader) question? – amdg Jan 10 '18 at 05:45
  • @amdg yes, thanks, but unfortunately, while it provided some guidance, it did not help resolve my particular case. I am using Spring Boot Starters and Gradle to load in the dependencies. I assume there no issues with the Spring Starters independently (as I am sure this would have been reported), but I am curious if anyone might be able to, based upon their knowledge of the Spring framework, point me to where the fault might be or there are some compatibility concerns (for example, loading spring-boot-starter-data-rest and spring-security-oauth2). Thanks. – KellyM Jan 10 '18 at 12:42
  • 2
    Just in case it helps anyone else, I found the issue. The conflict arose because of the version of mssql-jdbc driver I was using (it apparently depended on an old version of JsonSmart). Switching to a newer version resolved the conflict. Thanks. – KellyM Jan 10 '18 at 14:59
  • I have an identical stack trace, yet no mssql-jdbc driver :-/ – Edwin Diaz May 16 '18 at 18:29

1 Answers1

0

Managed to fix it by going to Open Module Settings -> Dependencies and delete the Test dependency com.jayway.jsonpath:json-path