Spring MVC Servlet XML文件配置


 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:p="http://www.springframework.org/schema/p"
 5     xmlns:mvc="http://www.springframework.org/schema/mvc"
 6     xmlns:context="http://www.springframework.org/schema/context"
 7     xsi:schemaLocation="http://www.springframework.org/schema/beans 
 8     http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
 9     http://www.springframework.org/schema/context
10     http://www.springframework.org/schema/context/spring-context-4.2.xsd
11     http://www.springframework.org/schema/mvc   
12     http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd">
13     
14     <!-- <bean id="login" class="com.mvc.LoginController"></bean>
15     <bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
16         <property name="mappings">
17             <props>
18                 <prop key="login.spring">login</prop>
19             </props>
20         </property>
21     </bean> -->
22     
23     <mvc:annotation-driven/><!-- 啟動注解驅動 -->
24     
25     <!--下一步啟用自動掃描:  -->
26     <context:component-scan base-package="com.mvc"></context:component-scan>
27     
28     <!-- ViewResolver視圖解析器 用於將返回的ModelAndView對象進行分離 :-->
29     <bean class="org.springframework.web.servlet.view.UrlBasedViewResolver">
30         <property name="viewClass"
31             value="org.springframework.web.servlet.view.JstlView"></property>
32         <property name="prefix" value="/"></property>
33         <property name="suffix" value=".jsp"></property>
34     </bean>
35     
36     <!-- jackson固定配置 :-->
37     <bean
38         class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
39         <property name="messageConverters">
40             <list>
41                 <ref bean="mappingJacksonHttpMessageConverter" />
42             </list>
43         </property>
44     </bean>
45     
46     <bean id="mappingJacksonHttpMessageConverter"
47         class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
48         <property name="supportedMediaTypes">
49             <list>
50                 <value>text/html;charset=UTF-8</value>
51             </list>
52         </property>
53     </bean>
54 </beans>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM