Spring配置

Posted on 2017-08-27 13:54  林浩开发小屋  阅读(132)  评论(0)    收藏  举报

一.web.xml配置

 

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <web-app id="WebApp_ID" version="2.4"
 3     xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 4     xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
 5     <display-name>Webapp Config</display-name>
 6 
 7     <context-param>
 8         <param-name>contextConfigLocation</param-name>
 9         <param-value>classpath:beans.xml</param-value>
10     </context-param>
11 
12     <!-- encode -->
13     <filter>
14         <filter-name>encode</filter-name>
15         <filter-class>
        org.springframework.web.filter.CharacterEncodingFilter
      </filter-class> 16 <init-param> 17 <param-name>encoding</param-name> 18 <param-value>UTF-8</param-value> 19 </init-param> 20 <init-param> 21 <param-name>forceEncoding</param-name> 22 <param-value>true</param-value> 23 </init-param> 24 </filter> 25 <filter-mapping> 26 <filter-name>encode</filter-name> 27 <url-pattern>/*</url-pattern> 28 </filter-mapping> 29 30 <listener> 31 <listener-class> 32 org.springframework.web.context.ContextLoaderListener 33 </listener-class> 34 </listener> 35 <servlet> 36 <servlet-name>springmvc</servlet-name> 37 <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 38 <init-param> 39 <param-name>contextConfigLocation</param-name> 40 <param-value>classpath:spring-mvc.xml</param-value> 41 </init-param> 42 <load-on-startup>1</load-on-startup> 43 </servlet> 44 <servlet-mapping> 45 <servlet-name>springmvc</servlet-name> 46 <url-pattern>/</url-pattern> 47 </servlet-mapping> 48 </web-app>

 

二 spring-mvc.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:context="http://www.springframework.org/schema/context"
 6     xmlns:tx="http://www.springframework.org/schema/tx"
 7     xmlns:aop="http://www.springframework.org/schema/aop"
 8     xmlns:mvc="http://www.springframework.org/schema/mvc"
 9     xsi:schemaLocation="http://www.springframework.org/schema/beans
10     http://www.springframework.org/schema/beans/spring-beans.xsd
11     http://www.springframework.org/schema/context
12     http://www.springframework.org/schema/context/spring-context.xsd
13     http://www.springframework.org/schema/aop
14     http://www.springframework.org/schema/aop/spring-aop.xsd
15     http://www.springframework.org/schema/tx 
16     http://www.springframework.org/schema/tx/spring-tx.xsd
17     http://www.springframework.org/schema/mvc 
18     http://www.springframework.org/schema/mvc/spring-mvc.xsd">
19     
20     <!-- 开启注解扫描-->
21     <context:component-scan base-package="netbank.firm.controller"/>
22 
23     <!-- 支持@RequestMapping请求和Controller 映射-->
24     <mvc:annotation-driven>
25 
26     <!-- 视图解析器 -->
27     <bean id="viewResolver"
28         class="org.springframework.web.servlet.view.InternalResourceViewResolver">
29         <property name="viewClass" value="org.springframework.web.servlet.view.JstlView">
30                 </property>
31         <property name="prefix" value="/WEB-INF/"></property>
32         <property name="suffix" value=".jsp"></property>
33         <property name="contentType">
34             <value>text/html;charset=UTF-8</value>
35         </property>
36     </bean>
37     
38     <!-- 定义文件上传处理器 -->
39     <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
40         <property name="defaultEncoding" value="utf-8" />
41         <property name="maxUploadSize" value="10485760000" />
42         <property name="maxInMemorySize" value="40960" />
43     </bean>
44         
45     <!-- AOP-->
46     <bean id="aspectBean" class="netbank.firm.interceptor.CurrentLinkAspect" /> 
47     <aop:config>
48         <aop:aspect id="controllerAspect" ref="aspectBean">
49             <aop:pointcut id="businessController" expression="execution(* netbank.firm.controller.*.*(..))" ></aop:pointcut>
50             <aop:before pointcut-ref="businessController" method="beforeCurrentLinkAspect"></aop:before>
51         </aop:aspect>
52     </aop:config>         
53 </beans>    

 

博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3