1. 程式人生 > >Spring配置

Spring配置

www. eba bus before let pat ram pattern per

一.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 
 6
<!--bean.xml 配置其他xml--> 7 <context-param> 8 <param-name>contextConfigLocation</param-name> 9 <param-value>classpath:beans.xml</param-value> 10 </context-param> 11 12 13 <!-- spring mvc --> 14 <servlet> 15
<servlet-name>springmvc</servlet-name> 16 <servlet-class> 17 org.springframework.web.servlet.DispatcherServlet 18 </servlet-class> 19 <init-param> 20 <param-name>contextConfigLocation</param-name> 21
<param-value>classpath:spring-mvc.xml</param-value> 22 </init-param> 23 <load-on-startup>1</load-on-startup> 24 </servlet> 25 <servlet-mapping> 26 <servlet-name>springmvc</servlet-name> 27 <url-pattern>/</url-pattern> 28 </servlet-mapping> 29 30 31 32 </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>    

Spring配置