Spring Kafka failed to resolve className - spring-boot

I am trying to send a data object from one spring service to another service using kafka.
The problem is that kafka is not able to resolve the className and hence is unable to map the consumber's class to the producer's class.
Following is the error message:
Caused by: org.springframework.messaging.converter.MessageConversionException: failed to resolve class name. Caused by: java.lang.ClassNotFoundException
I have tried to map the class using the following property:
For the producer: spring.kafka.producer.properties.spring.json.type.mapping=event:com.ankit.orderservice.event.OrderPlacedEvent
For the consumer: spring.kafka.consumer.properties.spring.json.type.mapping: event:com.ankit.OrderPlacedEvent

Related

NoSuchMethodError when trying to map Kafka binder to input method

The following is prompted in console when trying to launch a spring cloud streams project with the Kafka binder active:
org.springframework.context.ApplicationContextException: Failed to start bean 'inputBindingLifecycle';
Caused by: java.lang.NoSuchMethodError: java.util.List.of(Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Ljava/util/List;
My input method goes as follows using Spring Cloud functions:
#Bean
public Function<Message<String>, byte[]> exec() {
return input -> ...
Now, having Kafka in place, my .properties file looks as follows:
spring.cloud.stream.function.bindings.exec-in-0=in
spring.cloud.stream.bindings.in.destination=topic-0
spring.cloud.stream.function.bindings.exec-out-0=out
spring.cloud.stream.bindings.out.destination=topic-1
spring.cloud.stream.bindings.in.binder=kafka
spring.cloud.stream.kafka.bindings.in.consumer.configuration.value.deserializer=org.apache.kafka.common.serialization.StringDeserializer
spring.cloud.stream.bindings.out.binder=kafka
spring.cloud.stream.kafka.bindings.out.producer.configuration.value.serializer=org.apache.kafka.common.serialization.ByteArraySerializer
Am I missing any configs for the input method? Should that method be different for Kafka (already tested this with PubSub and it works)?
The error in your stack trace gives us a clue that you are facing this problem: https://github.com/spring-projects/spring-integration/issues/3761.
So, or upgrade to the latest Spring Cloud Stream: https://spring.io/projects/spring-cloud-stream#learn
Or to the latest Spring Integration: https://spring.io/projects/spring-integration#learn
Or just use Java > 8 !

How to consume an XML message from RabbitMQ in Spring Boot

My requirement is such that, i will be getting an application/xml message from rabbit mq, which has to be consumed by SpringBoot. I am able to get it as a string, but when I create an entity and try to get the xml as a java object, it throws the following error:
org.springframework.amqp.rabbit.listener.exception.ListenerExecutionFailedException: Listener method could not be invoked with the incoming message
and followed by
Caused by: org.springframework.messaging.converter.MessageConversionException: Cannot convert from [[B] to [com.boot.RabbitListener.Model.XmlEntity] for GenericMessage [payload=byte[4], headers={amqp_receivedDeliveryMode=NON_PERSISTENT, amqp_receivedRoutingKey=jsa.queue1, amqp_deliveryTag=1, amqp_consumerQueue=jsa.queue1, amqp_redelivered=false, id=0afca290-7ee2-36f5-4297-afeacbc451da, amqp_consumerTag=amq.ctag-HZO32UVNiMf9hWo_pAr9Bw, contentType=application/xml, timestamp=1542820548981}]
I am new to SpringBoot and i read some articles in marshler, but i am not sure on how to use it.
Provide a Jackson2XmlMessageConverter as Bean in your configuration as stated in the documentation:
#Bean
public Jackson2XmlMessageConverter xmlMessageConverter() {
return new Jackson2XmlMessageConverter();
}

Spring Integration serializes MessageHeader Object

i have some services, one implemented with Grails 2.4.2 (Spring 4.0.5) some implemented as Spring Web (Spring 4.0.5) and one implemented with Spring Boot 1.2.1 (Spring 4.1.4).
The services communicate over RabbitMQ with spring-integration.
Communication between Grails and the Spring Web services is fine, but it's not possible to communicate with the Spring Boot service. Because Spring Boot uses a newer Spring version and the serial version of the MessageHeader class has changed.
What can i do to avoid this problem?
Here the exception:
Caused by: org.springframework.messaging.MessagingException: Failure occured in AMQP listener while attempting to convert and dispatch Message.; nested exception is org.springframework.amqp.support.converter.MessageConversionException: failed to convert serialized
Message content
at org.springframework.integration.amqp.channel.AbstractSubscribableAmqpChannel$DispatchingMessageListener.onMessage(AbstractSubscribableAmqpChannel.java:201) ~[spring-integration-amqp-4.0.2.RELEASE.jar:na]
at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:693) ~[spring-rabbit-1.3.4.RELEASE.jar:na]
... 10 common frames omitted
Caused by: org.springframework.amqp.support.converter.MessageConversionException: failed to convert serialized Message content
at org.springframework.amqp.support.converter.SimpleMessageConverter.fromMessage(SimpleMessageConverter.java:112) ~[spring-amqp-1.3.4.RELEASE.jar:na]
at org.springframework.integration.amqp.channel.AbstractSubscribableAmqpChannel$DispatchingMessageListener.onMessage(AbstractSubscribableAmqpChannel.java:176) ~[spring-integration-amqp-4.0.2.RELEASE.jar:na]
... 11 common frames omitted
Caused by: java.lang.IllegalArgumentException: Could not deserialize object
at org.springframework.amqp.utils.SerializationUtils.deserialize(SerializationUtils.java:79) ~[spring-amqp-1.3.4.RELEASE.jar:na]
at org.springframework.amqp.support.converter.SimpleMessageConverter.fromMessage(SimpleMessageConverter.java:107) ~[spring-amqp-1.3.4.RELEASE.jar:na]
... 12 common frames omitted
Caused by: java.io.InvalidClassException: org.springframework.messaging.MessageHeaders; local class incompatible: stream classdesc serialVersionUID = -4615750558355702881, local class serialVersionUID = 7035068984263400920
at java.io.ObjectStreamClass.initNonProxy(ObjectStreamClass.java:617) ~[na:1.7.0_51]
at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1622) ~[na:1.7.0_51]
at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1517) ~[na:1.7.0_51]
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1771) ~[na:1.7.0_51]
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1350) ~[na:1.7.0_51]
> at org.springframework.amqp.utils.SerializationUtils.deserialize(SerializationUtils.java:76) ~[spring-amqp-1.3.4.RELEASE.jar:na]
Don't serialize the entire Message<?>; use the AMQP adapters' ability to map Message headers to amqp headers and vice-versa.
I am not sure how that works on the grails side but you'd need to do the mapping over there too.

com.ibm.ejs.container.ContainerEJBException: Unable to initialize deferred EJB

I am migrating my application from EJB2.0 to EJB3.0 and at the same migrating server from WAS5.0 to WAS7.0, I did all the changes required to migrate the EJB and has no compile time errors however when I deploy my EAR into the server and hit the application it gives me an error -
NMSV0605W: A javax.naming.Reference object looked up from the context "ejblocal:" with the name "ejb/com/freight/xyz/UserLocalHome" was sent to the JNDI Naming Manager and an exception resulted. Reference data follows:
Reference Factory Class Name: com.ibm.ejs.container.util.EJBLocalInterfaceObjectFactory
Reference Factory Class Location URLs: <null>
Reference Class Name: com.freight.xyz.UserLocalHome
Type: EJBLocalInterfaceInfo
Content: com.ibm.ejs.container.util.EJBLocalInterfaceInfo#5bb95bb9
Exception data follows:
com.ibm.ejs.container.ContainerEJBException: Unable to initialize deferred EJB.; nested exception is: java.lang.NoClassDefFoundError: com.freight.ecw.dto.User
at com.ibm.ws.runtime.component.EJBContainerImpl.initializeDeferredEJB(EJBContainerImpl.java:4938)
Along with this in the logs I can also see-
Exception stack trace: com.ibm.websphere.naming.CannotInstantiateObjectException: Exception occurred while the JNDI NamingManager was processing a javax.naming.Reference object.
Does anyone has any idea how to resolve this?

What's mean that Caused by: javax.validation.ValidationException: Unable to find a default provider?

I compiling springframework project using with springframework-3.0.1. But, I got error messages, "Caused by: javax.validation.ValidationException: Unable to find a default provider",
What is it? help me,
Do you actually have a ValidationProvider on your class path?
Try adding the reference implementation Hibernate Validator 4 to your class path.

Resources