1 <?xml version="1.0" encoding="UTF-8"?>
2 <beans xmlns="http://www.springframework.org/schema/beans"
3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4 xmlns:mvc="http://www.springframework.org/schema/mvc"
5 xmlns:context="http://www.springframework.org/schema/context"
6 xmlns:util="http://www.springframework.org/schema/util"
7 xmlns:p="http://www.springframework.org/schema/p"
9 http://www.springframework.org/schema/beans
10 http://www.springframework.org/schema/beans/spring-beans.xsd
11 http://www.springframework.org/schema/mvc
12 http://www.springframework.org/schema/mvc/spring-mvc.xsd
13 http://www.springframework.org/schema/context
14 http://www.springframework.org/schema/context/spring-context.xsd
15 http://www.springframework.org/schema/util
16 http://www.springframework.org/schema/util/spring-util.xsd">
19 I am declaring my beans without the automatic annotation. :/
20 Better because we are saving memory but it requires more configuration.
22 See: org.springframework.web.servlet.config.AnnotationDrivenBeanDefinitionParser
23 <mvc:annotation-driven/>
27 <context:annotation-config />
29 <context:component-scan base-package="de.spring.example.rest, org.resthub"/>
32 Required beans for generating XML responses from Java objects using JAXB annotations
33 Jackson also works but it doesn't generate XML with namespaces... O.o
35 This implementation will be slower than the one using Jackson :( but I am going to use it just for WADL generation :)
37 <bean id="jaxbMarshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
38 <property name="packagesToScan" value="org.jvnet.ws.wadl"/>
40 <bean id="jaxbConverter" class="org.springframework.http.converter.xml.MarshallingHttpMessageConverter">
41 <constructor-arg ref="jaxbMarshaller" />
44 <!-- Required beans for generating JSON responses from Java objects -->
45 <bean id="jsonObjectMapperFactory" class="org.springframework.http.converter.json.Jackson2ObjectMapperFactoryBean"
46 p:indentOutput="true" p:failOnEmptyBeans="false">
47 <property name="featuresToDisable">
49 <util:constant static-field="com.fasterxml.jackson.databind.DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES"/>
51 <!-- Useful when using Java 8 objects like OffsetDateTime.
52 I want to keep the offset in time zone if it exists.
54 LIKE THIS ONE: 2014-07-03 23:27:36+0100
56 <util:constant static-field="com.fasterxml.jackson.databind.DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE"/>
58 <util:constant static-field="com.fasterxml.jackson.databind.MapperFeature.DEFAULT_VIEW_INCLUSION"/>
63 <util:list id="messageConverters">
64 <bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter" p:objectMapper-ref="jsonObjectMapperFactory"/>
65 <ref bean="jaxbConverter" />
66 <bean class="org.springframework.http.converter.StringHttpMessageConverter" />
70 <bean name="handlerAdapter"
71 class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
72 <property name="webBindingInitializer">
74 class="org.springframework.web.bind.support.ConfigurableWebBindingInitializer">
75 <!-- It enables us to use JSR-303 -->
76 <property name="validator">
77 <bean class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean"/>
81 <property name="messageConverters" ref="messageConverters" />
84 <property name="requestBodyAdvice">
86 <bean id="requestBodyAdvice" class="org.springframework.web.servlet.mvc.method.annotation.JsonViewRequestBodyAdvice"/>
91 <property name="responseBodyAdvice">
93 <bean id="responseBodyAdvice" class="org.springframework.web.servlet.mvc.method.annotation.JsonViewResponseBodyAdvice"/>
98 <bean id="handlerMapping" class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping"/>
100 <mvc:default-servlet-handler />