I am working on a Desktop Application, with OpenJfx
and SpringBoot
. It works well thus far.
However, this application will consume a WebService and I want to use RestTemplate. When I add spring-web
dependency to my pom.xml file, Spring Boot attempts to instantiate several things for which I do not have use.
The dependency added:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>5.0.7.RELEASE</version>
</dependency>
First, the following error is displayed:
[2020-08-11 10:26:20] - WARN - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean. [AbstractApplicationContext.java:558]
I added the following propery, as per this response:
spring.main.web-application-type=none
Running the application again, more things attempt to instantiate:
[2020-08-11 10:29:47] - WARN - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'jacksonObjectMapper' defined in class path resource [org/springframework/boot/autoconfigure/jackson/JacksonAutoConfiguration$JacksonObjectMapperConfiguration.class]: Unsatisfied dependency expressed through method 'jacksonObjectMapper' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jacksonObjectMapperBuilder' defined in class path resource [org/springframework/boot/autoconfigure/jackson/JacksonAutoConfiguration$JacksonObjectMapperBuilderConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.http.converter.json.Jackson2ObjectMapperBuilder]: Factory method 'jacksonObjectMapperBuilder' threw exception; nested exception is java.lang.NoSuchMethodError: org.springframework.http.converter.json.Jackson2ObjectMapperBuilder.visibility(Lcom/fasterxml/jackson/annotation/PropertyAccessor;Lcom/fasterxml/jackson/annotation/JsonAutoDetect$Visibility;)Lorg/springframework/http/converter/json/Jackson2ObjectMapperBuilder; [AbstractApplicationContext.java:558]
[2020-08-11 10:29:47] - INFO -
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled. [ConditionEvaluationReportLoggingListener.java:136]
[2020-08-11 10:29:47] - ERROR -
***************************
APPLICATION FAILED TO START
***************************
Description:
An attempt was made to call a method that does not exist. The attempt was made from the following location:
org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration$Jackson2ObjectMapperBuilderCustomizerConfiguration$StandardJackson2ObjectMapperBuilderCustomizer.configureVisibility(JacksonAutoConfiguration.java:258)
The following method did not exist:
org.springframework.http.converter.json.Jackson2ObjectMapperBuilder.visibility(Lcom/fasterxml/jackson/annotation/PropertyAccessor;Lcom/fasterxml/jackson/annotation/JsonAutoDetect$Visibility;)Lorg/springframework/http/converter/json/Jackson2ObjectMapperBuilder;
The method's class, org.springframework.http.converter.json.Jackson2ObjectMapperBuilder, is available from the following locations:
jar:file:/C:/Users/xxx/.m2/repository/org/springframework/spring-web/5.0.7.RELEASE/spring-web-5.0.7.RELEASE.jar!/org/springframework/http/converter/json/Jackson2ObjectMapperBuilder.class
It was loaded from the following location:
file:/C:/Users/xxx/.m2/repository/org/springframework/spring-web/5.0.7.RELEASE/spring-web-5.0.7.RELEASE.jar
Action:
Correct the classpath of your application so that it contains a single, compatible version of org.springframework.http.converter.json.Jackson2ObjectMapperBuilder
[LoggingFailureAnalysisReporter.java:40]
The problem is, I only want to use RestTemplate to consume a Rest Service. Is there a way I can add Classes native to other spring libraries, without all the additional baggage?