开发者

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

开发者 https://www.devze.com 2023-02-04 10:06 出处:网络
I am writing a RESTful web service using JAXB and Spring MVC. In my Spring contexttakes care of a lot of helpful stuff for me, but it registers its own JAXB marshaller and I can\'t find a way to开发者

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开发者_JAVA技巧 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?


<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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号