i have a JMS "endpoint" like this:
@JmsListener(destination = "TestQueue")
public void doSomething(MyJaxbAnnotatedClass myclass) {
}
Of course with the needed applicationContext configuration like <jms:annotation-driven/> and the likes. All this worked when my method signature was only a
public void doSomething(String xmlString)
But i want to have automatic unmarshalling done by Spring like i do it with JSON in the Spring-MVC context. But somehow Spring needs more configuration for this to happen, because i get the following stacktrace when trying the MyJaxbAnnotatedClass parameter:
Caused by: org.springframework.messaging.converter.MessageConversionException: No converter found to convert to class de.xxx.xxx.MyJaxbAnnotatedClass, message=GenericMessage [payload=<BRNArtikelStamm:EcomxProducts
xmlns:BRNfoo="http://www.xxx.xxx/foofoo"
So i assume i must somehow tell Spring how to unmarshal? Since JAXB is a pretty common way of doing serialization, i hope there is a common config which needs to be applied.
Thanks for any input.
You need to register a message converter that is able to do that, pretty much as you have to do for any non trivial conversion.
Since you're obviously using the default JmsListerContainerFactory
, extend it to register a message converter for your listener, someething like:
@Bean
public DefaultJmsListenerContainerFactory jmsListenerContainerFactory() {
DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
factory.setConnectionFactory(connectionFactory());
factory.setMessageConverter(jmsMessageConverter());
return factory;
}
Your jmsMessageConverter
defines how messages are deserialized (you can reuse the same instance on the produce side). Try MarshallingMessageConverter
with Jaxb2Marshaller
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With