Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I configure the Jaxb2Marshaller used by mvc:annotation-driven

I am writing a RESTful web service using JAXB and Spring MVC. In my Spring context takes care of a lot of helpful stuff for me, but it registers its own JAXB marshaller and I can't find a way to add properties to it (like a NamespacePrefixMapper or schema location).

Is there a way to override the default marshaller configured in or set properties on it?

like image 723
rjsang Avatar asked Nov 14 '22 04:11

rjsang


1 Answers

<mvc:annotation-driven> is essentially a "macro" that registers a bunch of fixed config options. You can see what it does in the source of the rather dense AnnotationDrivenBeanDefinitionParser class.

Of particular interest here is that it registers a AnnotationMethodHandlerAdapter and injects a whole series of components into it, some of which you'll need, many of which you won't.

<mvc:annotation-driven> doesn't offer much in the way of customisation, though, so if you want to change what it does, you need to remove it from your context, and declare your own AnnotationMethodHandlerAdapter, configured the way you want.

The JAXB marshaller is injected into the messageConverters property of AnnotationMethodHandlerAdapter.

like image 198
skaffman Avatar answered Dec 08 '22 01:12

skaffman