1 <beans xmlns="http://www.springframework.org/schema/beans"
2 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3 xmlns:mvc="http://www.springframework.org/schema/mvc"
4 xmlns:context="http://www.springframework.org/schema/context"
5 xmlns:util="http://www.springframework.org/schema/util"
6 xmlns:p="http://www.springframework.org/schema/p"
7 xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
8 http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
9 http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
10 http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">
13 I am declaring my beans without the automatic annotation. :/
14 Better because we are saving memory but it requires more configuration.
16 See: org.springframework.web.servlet.config.AnnotationDrivenBeanDefinitionParser
17 <mvc:annotation-driven/>
19 <!-- Required for making work @ControllerAdvice and setting our custom return value handlers -->
20 <mvc:annotation-driven>
21 <mvc:return-value-handlers>
22 <bean class="org.springframework.cloud.netflix.rx.SingleReturnValueHandler" />
23 </mvc:return-value-handlers>
24 </mvc:annotation-driven>
27 Instead of annotation-driven we could use @EnableWebMvc (Java code instead of XML files)
29 If annotation-driven works with org.springframework.web.servlet.config.AnnotationDrivenBeanDefinitionParser
30 @EnableWebMvc does the same with org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport
32 Here I am using XML fiels intead of Java code :/
35 <context:annotation-config />
37 <context:component-scan base-package="de.spring.webservices.rest, org.springframework.cloud.netflix.rx"/>
40 Required beans for generating XML responses from Java objects using JAXB annotations
41 Jackson also works but it doesn't generate XML with namespaces... O.o
43 This implementation will be slower than the one using Jackson :( but I am going to use it just for WADL generation :)
45 <bean id="jaxbMarshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
46 <property name="packagesToScan" value="org.jvnet.ws.wadl"/>
48 <bean id="jaxbConverter" class="org.springframework.http.converter.xml.MarshallingHttpMessageConverter">
49 <constructor-arg ref="jaxbMarshaller" />
52 <!-- Required beans for generating JSON responses from Java objects -->
53 <bean id="jsonObjectMapperFactory" class="org.springframework.http.converter.json.Jackson2ObjectMapperFactoryBean"
54 p:indentOutput="true" p:failOnEmptyBeans="false">
55 <property name="featuresToDisable">
57 <util:constant static-field="com.fasterxml.jackson.databind.DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES"/>
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" />
83 <property name="requestBodyAdvice">
85 <bean id="requestBodyAdvice" class="org.springframework.web.servlet.mvc.method.annotation.JsonViewRequestBodyAdvice"/>
90 <property name="responseBodyAdvice">
92 <bean id="responseBodyAdvice" class="org.springframework.web.servlet.mvc.method.annotation.JsonViewResponseBodyAdvice"/>
97 <bean id="handlerMapping" class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping"/>
99 <mvc:default-servlet-handler />