Spring-Boot 2.1.2 and class com.fasterxml.jackson.annotation.JsonInclude - spring-boot

My Sprint boot application is not coming up because it's complaining about missing class com.fasterxml.jackson.annotation.JsonInclude$Value, but I have jackson library as dependency, so I think it might be possible some conflict.
SPRING LOG:
:: Spring Boot :: (v2.1.2.RELEASE)
00:22:54.084 [main ] ERROR ngframework.boot.web.embedded.tomcat.TomcatStarter - Error starting Tomcat context. Exception: org.springframework.beans.factory.BeanCreationException. Message: Error creating bean with name 'formContentFilter' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.web.servlet.filter.OrderedFormContentFilter]: Factory method 'formContentFilter' threw exception; nested exception is java.lang.NoClassDefFoundError: Could not initialize class com.fasterxml.jackson.annotation.JsonInclude$Value
00:22:55.063 [main ] ERROR org.springframework.boot.SpringApplication - Application run failed
pom.xml (dependencies):
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.1.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>2.1.2.RELEASE</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.4</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.9.4</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.9.4</version>
</dependency>
Has anybody already faced similar issue?
Thanks

jackson-core,jackson-annotations and jackson-databind jars are automatically added by spring boot.
so you don't need to add them explicitly unless you want to override the version of the jar that are provided by spring boot .

Use the below version for both the artefacts:
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.10.0.pr1</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.9.4</version>
</dependency>
Also, update the maven-compiler-plugin version to the latest if maven build fails.
Jackson has made some changes in the method signature of class ObjectMapper, handle the same if implemented.

Related

Error 'org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration$EmbeddedTomcat' in gRPC Spring Boot Client

I am getting below error while starting spring boot grpc client application. Getting this error within GrpcClientBeanPostProcessor processing
org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext WARN Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration$EmbeddedTomcat': Initialization of bean failed; nested exception is java.lang.AbstractMethodError
Below are the dependencies:
<java.version>1.8</java.version>
<grpc.version>1.47.0</grpc.version>
<protoc.version>3.5.1</protoc.version>
<protobuf-maven-plugin.version>0.6.1</protobuf-maven-plugin.version>
-------
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.6.RELEASE</version>
</parent>
-------
<dependency>
<groupId>net.devh</groupId>
<artifactId>grpc-client-spring-boot-starter</artifactId>
<version>2.9.0.RELEASE</version>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-protobuf</artifactId>
<version>${grpc.version}</version>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-stub</artifactId>
<version>${grpc.version}</version>
</dependency>
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java-util</artifactId>
<version>3.12.2</version>
</dependency>
Need to have guava latest for resolving this. Working fine with the below.
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>23.6-jre</version>
</dependency>

java.lang.NoSuchMethodError: org.springframework.beans.factory.support.CglibSubclassingInstantiationStrategy

I have upgraded my Spring framework from 3.1.0 to 3.2.18.
Then I am getting below exception.
org.springframework.beans.factory.BeanCreationException: Error creating bean
with name 'myService' defined in class path resource
[spring-biproxy-context.xml]: Instantiation of bean failed; nested
exception is java.lang.NoSuchMethodError: org.springframework.beans.factory.support.CglibSubclassingInstantiationStrategy$CglibSubclassCreator$LookupOverrideMethodInterceptor: method (Lorg/springframework/beans/factory/support/CglibSubclassingInstantiationStrategy$CglibSubclassCreator;Lorg/springframework/beans/factory/support/CglibSubclassingInstantiationStrategy$1;)V not found
I did not make any code changes. Only altered the spring version.
Looks like spring framework removed class called LookupOverrideMethodInterceptor in 3.2.18 But in runtime, spring is looking for this class.
Spring_bean_jar_diff
pom.xml
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>3.2.18</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>3.2.18</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>3.2.18</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>3.2.18</version>
<scope>compile</scope>
</dependency>

Error: nested exception is java.lang.NoClassDefFoundError: com/fasterxml/jackson/annotation/JsonMerge

i am configuring the ajax json function in the Spring MVC 3.0 Maven project and get the error message that "nested exception is java.lang.NoClassDefFoundError: com/fasterxml/jackson/core/JsonProcessingException".
So, what should i do to configure the pom.xml to install the needed classes?
Any suggestions would be very helpful!
Add below dependencies to your pom.xml
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>${jackson.version}</version>
</dependency>
Replace ${jackson.version} with any version you want,or just add 2.x.xat top of your pom.xml

Issue with Spring Data (Spring Boot) and Joda Time field mapping

I have some entities with Joda DateTime fields.
When trying to start the application, I get the following error:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: org.hibernate.engine.spi.SessionFactoryImplementor.getProperties()Ljava/util/Map;
[...]
Caused by: java.lang.NoSuchMethodError: org.hibernate.engine.spi.SessionFactoryImplementor.getProperties()Ljava/util/Map;
at org.jadira.usertype.spi.shared.AbstractUserTypeHibernateIntegrator.integrate(AbstractUserTypeHibernateIntegrator.java:192) ~[usertype.spi-6.0.1.GA.jar:na]
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:280) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:444) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:879) ~[hibernate-entitymanager-5.0.11.Final.jar:5.0.11.Final]
I tried to put
spring.jpa.properties.jadira.usertype.autoRegisterUserTypes=true
in the application.properties and it didn't work. So I added the Hibernate annotation into my entity class:
#Type(type="org.jadira.usertype.dateandtime.joda.PersistentDateTime")
private DateTime from;
and it didn't work.
My pom.xml (partial):
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
</dependency>
<dependency>
<groupId>org.jadira.usertype</groupId>
<artifactId>usertype.core</artifactId>
<version>6.0.1.GA</version>
</dependency>
<!-- Jackson json data bind -->
<dependency>
<groupId>com.fasterxml.jackson.jaxrs</groupId>
<artifactId>jackson-jaxrs-json-provider</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-joda</artifactId>
</dependency>
I also tried Jadira usertype.core 6.0.0.GA, 5.0.0.GA and 4.0.0.GA but nothing changes. How can I fix that?
====================EDIT
Debugging led me to line 192 of the class AbstractUserTypeHibernateIntegrator
String isEnabled = (String)sessionFactory.getProperties().get("jadira.usertype.autoRegisterUserTypes");
My debugger says the value assigned to isEnabled is the "true". However, the execution jumps to the finally clause: ConfigurationHelper.setCurrentSessionFactory((SessionFactory)null)
The signature of SessionFactoryImplementor.getProperties() changed in 5.2 to return Map rather than Properties. This leads to a NoSuchMethodError if hibernate version is lower than that. And also make sure to use latest jadira jar which is compatible with Hibernate 5.2
Add these dependencies in your pom.xml
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.2.0.Final</version>
</dependency>
<dependency>
<groupId>org.jadira.usertype</groupId>
<artifactId>usertype.core</artifactId>
<version>6.0.1.GA</version>
</dependency>
The reason for the above issue is that you forgot to add the entitiyManager dependency.
Try adding the below dependency
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.3.8.Final</version>
</dependency>
This is what worked for me with spring boot, the problem is that Spring boot version 1.5.4 data-jpa starter has hibernate-core and hibernate-entitymanager version 5.0.12 which is incompatible with jadira version 6.0.1.GA so we have to override these in pom.xml and provide version 5.2.0.Final at least ( I have used 5.2.10.Final in the code as this is the latest one at the time of writting).
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
</dependency>
<dependency>
<groupId>org.jadira.usertype</groupId>
<artifactId>usertype.core</artifactId>
<version>6.0.1.GA</version>
</dependency>
<!-- Jackson json data bind -->
<dependency>
<groupId>com.fasterxml.jackson.jaxrs</groupId>
<artifactId>jackson-jaxrs-json-provider</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-joda</artifactId>
</dependency>
<!-- Spring boot version 1.5.4 has hibernate-core 5.0.12 which is incompatible with jadira version 6.0.1.GA -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.2.10.Final</version>
</dependency>
<!-- Spring boot version 1.5.4 has hibernate-entitymanager 5.0.12 which is incompatible with jadira version 6.0.1.GA -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>5.2.10.Final</version>
</dependency>

Dependency clash between Apache CXF and Kie Remote Client

I'm currently writing an Apache Camel project that's using CXF to expose some REST endpoints and Kie Remote Client to interface with BPMS. However, I'm getting a dependency clash (not sure how to describe it) when I try to include the Kie Remote Client dependency into my pom file.
Here's my pom file currently:
<dependencies>
<!-- Camel Dependencies -->
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-core</artifactId>
<version>2.15.2</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-cxf</artifactId>
<version>2.15.2</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-spring</artifactId>
<version>2.15.2</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-jackson</artifactId>
<version>2.15.2</version>
</dependency>
<!-- Spring Web -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>4.1.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>4.1.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-jaxrs</artifactId>
<version>1.9.12</version>
</dependency>
<!-- <dependency>
<groupId>org.kie</groupId>
<artifactId>kie-parent-with-dependencies</artifactId>
<version>6.2.0.Final-redhat-4</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.kie.remote</groupId>
<artifactId>kie-remote-client </artifactId>
<version>6.2.0.Final-redhat-4</version>
<scope>provided</scope>
</dependency> -->
</dependencies>
When I try to deploy my project I'm getting some property exceptions:
Caused by: org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (2) are:
PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'serviceBeans' threw exception; nested exception is java.lang.NoSuchMethodError: org.apache.cxf.jaxrs.JAXRSServerFactoryBean.addToBeans(Ljava/util/Collection;Ljava/lang/Object;)V
PropertyAccessException 2: org.springframework.beans.MethodInvocationException: Property 'providers' threw exception; nested exception is java.lang.NoSuchMethodError: org.apache.cxf.jaxrs.AbstractJAXRSFactoryBean.addToBeans(Ljava/util/Collection;Lj ava/lang/Object;)V
at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractProp ertyAccessor.java:121) [spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:75) [spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.appl yPropertyValues(AbstractAutowireCapableBeanFactory.java:1510) [spring-beans- 4.1.6.RELEASE.jar:4.1.6
Anyone know what's the root cause of this error? Thanks!
EDIT: I did find a temporary workaround to this problem. If I downgrade my camel versions to 2.13.2 and my spring versions to 3.2.8-RELEASE then the apache-cxf versions seem to aligh. However there are many new features that I need in 2.15.2 camel that I would like to keep. Anyone know of any good alternatives to kie.remote.client?
Kie remote client add the jaxb-impl-2.2.5.jar dependency, in collition with jaxb-core-2.2.11.jar and jaxb-impl-2.2.11.jar from cxf.
just remove the jaxb-impl from you deploy. (or use maven exclusion in dependency of kie-client) it's works for me.

Resources