5ce72efb0c30ff844b08f507cc7b64cafeb8688d
[JavaForFun] /
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="
8                 http://www.springframework.org/schema/beans
9                 http://www.springframework.org/schema/beans/spring-beans.xsd
10         http://www.springframework.org/schema/mvc
11         http://www.springframework.org/schema/mvc/spring-mvc.xsd
12         http://www.springframework.org/schema/context
13         http://www.springframework.org/schema/context/spring-context.xsd
14         http://www.springframework.org/schema/util
15         http://www.springframework.org/schema/util/spring-util.xsd">
16    
17         <!--
18                 I am declaring my beans without the automatic annotation. :/
19                 Better because we are saving memory but it requires more configuration.
20                 
21                 See: org.springframework.web.servlet.config.AnnotationDrivenBeanDefinitionParser
22                 <mvc:annotation-driven/>
23          -->
24          
25    
26         <context:annotation-config />
27    
28         <context:component-scan base-package="de.spring.webservices.rest"/>
29         
30         <!--
31                 Required beans for generating XML responses from Java objects using JAXB annotations
32                 Jackson also works but it doesn't generate XML with namespaces... O.o
33                 
34                 This implementation will be slower than the one using Jackson :( but I am going to use it just for WADL generation :)
35         -->    
36     <bean id="jaxbMarshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
37         <property name="packagesToScan" value="org.jvnet.ws.wadl"/>
38     </bean>
39         <bean id="jaxbConverter" class="org.springframework.http.converter.xml.MarshallingHttpMessageConverter">
40         <constructor-arg ref="jaxbMarshaller" />
41         </bean>
42     
43         <!-- Required beans for generating JSON responses from Java objects -->
44     <bean id="jsonObjectMapperFactory" class="org.springframework.http.converter.json.Jackson2ObjectMapperFactoryBean"
45         p:indentOutput="true" p:failOnEmptyBeans="false">
46         <property name="featuresToDisable">
47             <array>
48                 <util:constant static-field="com.fasterxml.jackson.databind.DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES"/>
49                 <util:constant static-field="com.fasterxml.jackson.databind.MapperFeature.DEFAULT_VIEW_INCLUSION"/>
50             </array>
51         </property>
52     </bean>
53     
54     <util:list id="messageConverters">
55         <bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter" p:objectMapper-ref="jsonObjectMapperFactory"/>
56                 <ref bean="jaxbConverter" />
57         <bean class="org.springframework.http.converter.StringHttpMessageConverter" />
58     </util:list>
59
60
61         <bean name="handlerAdapter"
62                 class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
63                 <property name="webBindingInitializer">
64                         <bean
65                                 class="org.springframework.web.bind.support.ConfigurableWebBindingInitializer">
66                                 <!-- It enables us to use JSR-303 -->
67                                 <property name="validator">
68                                         <bean class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean"/>
69                                 </property>
70                         </bean>
71                 </property>
72                 <property name="messageConverters" ref="messageConverters" />
73                 
74                 
75                 <property name="requestBodyAdvice">
76                         <util:list>
77                                 <bean id="requestBodyAdvice" class="org.springframework.web.servlet.mvc.method.annotation.JsonViewRequestBodyAdvice"/>
78                         </util:list>
79                 </property>
80                 
81                 
82                 <property name="responseBodyAdvice">
83                         <util:list>
84                                 <bean id="responseBodyAdvice" class="org.springframework.web.servlet.mvc.method.annotation.JsonViewResponseBodyAdvice"/>
85                         </util:list>
86                 </property>
87         </bean>
88     
89         <bean id="handlerMapping" class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping"/>
90
91         <mvc:default-servlet-handler />
92         
93 </beans>