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"/>
61 <property name="modulesToInstall" ref="customJacksonModules"/>
64 <util:list id="messageConverters">
65 <bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter" p:objectMapper-ref="jsonObjectMapperFactory"/>
66 <ref bean="jaxbConverter" />
67 <bean class="org.springframework.http.converter.StringHttpMessageConverter" />
71 <bean name="handlerAdapter"
72 class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
73 <property name="webBindingInitializer">
75 class="org.springframework.web.bind.support.ConfigurableWebBindingInitializer">
76 <!-- It enables us to use JSR-303 -->
77 <property name="validator">
78 <bean class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean"/>
82 <property name="messageConverters" ref="messageConverters" />
85 <property name="requestBodyAdvice">
87 <bean id="requestBodyAdvice" class="org.springframework.web.servlet.mvc.method.annotation.JsonViewRequestBodyAdvice"/>
92 <property name="responseBodyAdvice">
94 <bean id="responseBodyAdvice" class="org.springframework.web.servlet.mvc.method.annotation.JsonViewResponseBodyAdvice"/>
99 <bean id="handlerMapping" class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping"/>
102 <util:list id="customJacksonModules">
104 <value type="java.lang.Class">de.spring.example.rest.resource.modules.SpringJpaModule</value>
108 <mvc:default-servlet-handler />