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