码迷,mamicode.com
首页 > 编程语言 > 详细

比较全的SpringMVC配置文件

时间:2016-06-13 22:15:09      阅读:311      评论:0      收藏:0      [点我收藏+]

标签:

  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" xmlns:tx="http://www.springframework.org/schema/tx"
  4     xmlns:context="http://www.springframework.org/schema/context"
  5     xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:aop="http://www.springframework.org/schema/aop"
  6     xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
  7         http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
  8         http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
  9         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
 10         http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
 11 
 12     <!-- 配置databaseSource -->
 13     <!-- ====================================== -->
 14     <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
 15         <property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
 16         <property name="url"
 17             value="jdbc:mysql://localhost:3306/storemanager?characterEncoding=utf-8"></property>
 18         <property name="username" value="root"></property>
 19         <property name="password" value="123456"></property>
 20         <!-- 连接池初始化连接个数 -->
 21         <property name="initialSize" value="3" />
 22         <!-- 连接池的最大值 -->
 23         <property name="maxActive" value="10" />
 24         <!-- 最大空闲值.当经过一个高峰时间后,连接池可以慢慢将已经用不到的连接慢慢释放一部分,一直减少到maxIdle为止 -->
 25         <property name="maxIdle" value="5" />
 26         <!-- 最小空闲值.当空闲的连接数少于阀值时,连接池就会预申请去一些连接,以免洪峰来时来不及申请 -->
 27         <property name="minIdle" value="2" />
 28         <!-- 获取连接最大等待时间 -->
 29         <!-- <property name="maxWait" value="60000" /> -->
 30 
 31         <!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 -->
 32         <property name="timeBetweenEvictionRunsMillis" value="60000" />
 33         <!-- 配置一个连接在池中最小生存的时间,单位是毫秒 -->
 34         <property name="minEvictableIdleTimeMillis" value="25200000" />
 35         <!-- 打开removeAbandoned功能 -->
 36         <property name="removeAbandoned" value="true" />
 37         <!-- 1800秒,也就是30分钟 -->
 38         <property name="removeAbandonedTimeout" value="1800" />
 39         <!-- 关闭abanded连接时输出错误日志 -->
 40         <property name="logAbandoned" value="true" />
 41         <!-- 监控数据库 -->
 42         <!-- <property name="filters" value="mergeStat" /> -->
 43         <!-- <property name="filters" value="stat" /> -->
 44     </bean>
 45 
 46     <!-- 配置sessionFactory,用于获取session -->
 47     <!-- ====================================== -->
 48     <bean id="sessionFactory"
 49         class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
 50         <property name="dataSource">
 51             <ref bean="dataSource" />
 52         </property>
 53         <property name="mappingResources">
 54             <list>
 55                 <value>com/kl/napchen/store/bean/User.hbm.xml</value>
 56                 <value>com/kl/napchen/store/bean/ProductIn.hbm.xml</value>
 57                 <value>com/kl/napchen/store/bean/ProductOut.hbm.xml</value>
 58                 <value>com/kl/napchen/store/bean/ProductType.hbm.xml</value>
 59             </list>
 60         </property>
 61         <property name="hibernateProperties">
 62             <props>
 63                 <prop key="hibernate.dialect">
 64                     org.hibernate.dialect.MySQL5Dialect
 65                 </prop>
 66                 <prop key="hibernate.hbm2ddl.auto">update</prop>
 67                 <prop key="hibernate.format_sql">true</prop>
 68                 <prop key="hibernate.show_sql">true</prop>
 69                 <prop key="current_session_context_class">thread</prop>
 70             </props>
 71         </property>
 72 
 73         <!-- 自动扫描注解方式配置的hibernate类文件 -->
 74         <!-- <property name="packagesToScan"> -->
 75         <!-- <list> -->
 76         <!-- <value>light.mvc.model</value> -->
 77         <!-- </list> -->
 78         <!-- </property> -->
 79     </bean>
 80 
 81     <!-- 配置事务管理器 -->
 82     <!-- ====================================== -->
 83     <bean id="transactionManager"
 84         class="org.springframework.orm.hibernate4.HibernateTransactionManager">
 85         <property name="sessionFactory" ref="sessionFactory" />
 86         <!-- <property name="rollbackOnCommitFailure" value="true" /> -->
 87     </bean>
 88 
 89     <!-- 注解方式配置事物 -->
 90     <!-- ====================================== -->
 91     <!-- <tx:annotation-driven transaction-manager="transactionManager" /> -->
 92 
 93     <!-- AOP方式配置事物 -->
 94     <!-- ====================================== -->
 95     <tx:advice id="transactionAdvice" transaction-manager="transactionManager">
 96         <tx:attributes>
 97             <!-- <tx:method name="get*" propagation="REQUIRED" read-only="true" /> -->
 98             <!-- <tx:method name="add*" propagation="REQUIRED" /> -->
 99             <tx:method name="delete" propagation="REQUIRED" />
100             <tx:method name="*" propagation="REQUIRED" />
101         </tx:attributes>
102     </tx:advice>
103 
104     <aop:config>
105         <aop:pointcut id="transactionPointcut"
106             expression="execution(* com.kl.napchen.store.impl..*.*(..))" />
107         <aop:advisor pointcut-ref="transactionPointcut"
108             advice-ref="transactionAdvice" />
109     </aop:config>
110 
111     <!-- 启用aspectj注解自动代理 -->
112     <!-- ====================================== -->
113     <aop:aspectj-autoproxy />
114 
115     <!-- 配置代理bean -->
116     <!-- ====================================== -->
117     <bean id="adviceLog" class="com.kl.napchen.store.annotation.AdviceLog"></bean>
118     <bean id="adviceUserLog" class="com.kl.napchen.store.annotation.AdviceUserLog"></bean>
119 
120     <!-- 配置Bean -->
121     <!-- ====================================== -->
122     <bean id="user" class="com.kl.napchen.store.bean.User"></bean>
123     <bean id="productIn" class="com.kl.napchen.store.bean.ProductIn"></bean>
124     <bean id="productOut" class="com.kl.napchen.store.bean.ProductOut"></bean>
125     <bean id="productType" class="com.kl.napchen.store.bean.ProductType"></bean>
126     <bean id="sessionInfo" class="com.kl.napchen.store.global.SessionInfo"></bean>
127     <bean id="pageGrid" class="com.kl.napchen.store.page.PageGrid"></bean>
128 
129     <!-- 配置操作数据的Dao -->
130     <!-- ====================================== -->
131     <bean id="userDao" class="com.kl.napchen.store.dao.UserDao"></bean>
132     <bean id="productInDao" class="com.kl.napchen.store.dao.ProductInDao"></bean>
133     <bean id="productOutDao" class="com.kl.napchen.store.dao.ProductOutDao"></bean>
134     <bean id="productTypeDao" class="com.kl.napchen.store.dao.ProductTypeDao"></bean>
135 
136     <!-- 配置业务处理的service -->
137     <!-- ====================================== -->
138     <bean id="userImpl" class="com.kl.napchen.store.impl.UserImpl"></bean>
139     <bean id="productInImpl" class="com.kl.napchen.store.impl.ProductInImpl"></bean>
140     <bean id="productOutImpl" class="com.kl.napchen.store.impl.ProductOutImpl"></bean>
141     <bean id="productTypeImpl" class="com.kl.napchen.store.impl.ProductTypeImpl"></bean>
142 
143     <!-- 配置控制流程的controller -->
144     <!-- ====================================== -->
145     <!-- <bean id="userController" class="com.kl.napchen.store.controller.UserController"></bean> -->
146     <!-- <bean id="productInController" class="com.kl.napchen.store.controller.ProductInController"></bean> -->
147     <!-- <bean id="productOutController" class="com.kl.napchen.store.controller.ProductOutController"></bean> -->
148     <!-- <bean id="productTypeController" class="com.kl.napchen.store.controller.ProductTypeController"></bean> -->
149 
150 
151     <!-- 配置获取spring容器中Bean的工具Bean -->
152     <!-- 由于持有ApplicationContext, -->
153     <!-- 可以使用SpringContextHolder.getBean(‘xx‘)的静态方法得到spring bean对象 -->
154     <!-- ====================================== -->
155     <!-- <bean class="com.kl.napchen.storeManagerSystem.contextHolder.SpringContextHolder" 
156         lazy-init="false" /> -->
157 
158     <!-- 对静态资源文件的访问 方案一 (二选一) -->
159     <!-- 使用"*.do"配置DispatcherServlet时不存在静态资源访问问题 ,拦截器将不会拦截静态资源的URL -->
160     <!-- 使用"/"配置DispatcherServlet时存在静态资源访问问题,采用以下两种方案解决 -->
161     <!-- ====================================== -->
162     <mvc:default-servlet-handler />
163 
164     <!-- 对静态资源文件的访问 方案二 (二选一) -->
165     <!-- ====================================== -->
166     <!-- 静态资源映射 -->
167     <!-- <mvc:resources mapping="/js/**" location="/WEB-INF/js/" /> -->
168     <!-- <mvc:resources mapping="/css/**" location="/WEB-INF/css/" /> -->
169     <!-- <mvc:resources mapping="/fonts/**" location="/WEB-INF/fonts/" /> -->
170     <!-- <mvc:resources mapping="/plugins/**" location="/WEB-INF/plugins/" /> -->
171     <!-- <mvc:resources mapping="images/**" location="/WEB-INF/images/" /> -->
172 
173     <!-- 默认的注解映射的支持 -->
174     <!-- 采用这下面种方式将自动装配DefaultAnnotationHandlerMapping和AnnotationMethodHandlerAdapter -->
175     <!-- 采用这下面种方式将无法在 DefaultAnnotationHandlerMapping配置拦截器 -->
176     <!-- ====================================== -->
177     <mvc:annotation-driven />
178 
179     <!-- 配置 DefaultAnnotationHandlerMapping和AnnotationMethodHandlerAdapter -->
180     <!-- ====================================== -->
181     <!-- <bean -->
182     <!-- class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"> -->
183     <!-- 配置拦截器 -->
184     <!-- <property name="interceptors"> -->
185     <!-- <list> -->
186     <!-- <bean class="com/kl/napchen/storeManagerSystem/interceptor/MyInterceptor"></bean> -->
187     <!-- </list> -->
188     <!-- </property> -->
189     <!-- </bean> -->
190     <!-- <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"> 
191         </bean> -->
192 
193     <!-- 隐式地向 Spring容器注册这4个BeanPostProcessor -->
194     <!-- AutowiredAnnotationBeanPostProcessor、 -->
195     <!-- RequiredAnnotationBeanPostProcessor、 -->
196     <!-- CommonAnnotationBeanPostProcessor、 -->
197     <!-- PersistenceAnnotationBeanPostProcessor -->
198     <!-- ====================================== -->
199     <!-- <context:annotation-config /> -->
200 
201 
202     <!-- 设置使用注解的类所在的jar包 ,使用这种即可省去上面的声明 -->
203     <!-- ====================================== -->
204     <context:component-scan base-package="com.kl.napchen.store.controller" />
205     <context:component-scan base-package="com.kl.napchen.store.impl" />
206     <context:component-scan base-package="com.kl.napchen.store.baseService" />
207 
208 
209     <!-- 映射“/”的url -->
210     <!-- ====================================== -->
211     <!-- <mvc:view-controller path="/" view-name="forward:/index2" /> -->
212 
213     <!-- configure the InternalResourceViewResolver -->
214     <bean
215         class="org.springframework.web.servlet.view.InternalResourceViewResolver"
216         id="internalResourceViewResolver">
217         <!-- <property name="viewClass" value="org.springframework.web.servlet.view.JstlView" 
218             /> -->
219         <!-- 前缀 -->
220         <property name="prefix" value="/WEB-INF/jsp/" />
221         <!-- 后缀 -->
222         <property name="suffix" value=".jsp" />
223     </bean>
224 
225     <!-- 自定义拦截器 (近似-总拦截器) -->
226     <!-- ====================================== -->
227     <mvc:interceptors>
228         <!-- 使用bean定义一个Interceptor,直接定义在mvc:interceptors根下面的Interceptor将拦截所有的请求 -->
229         <bean class="com.kl.napchen.store.interceptor.MyInterceptor" />
230     </mvc:interceptors>
231 
232 
233     <!-- 总错误处理 -->
234     <!-- ====================================== -->
235     <bean id="exceptionResolver"
236         class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
237         <!-- 配置不同类别的错误对应的view和状态码 -->
238         <property name="exceptionMappings">
239             <props>
240                 <prop key="java.lang.Exception">errors/error</prop>
241                 <prop key="java.lang.Throwable">errors/error</prop>
242                 <!-- 上传文件大于最大尺寸后转向出错页面 -->
243                 <!-- ====================================== -->
244                 <prop
245                     key="org.springframework.web.multipart.MaxUploadSizeExceededException">errors/uploadError
246                 </prop>
247             </props>
248         </property>
249         <property name="statusCodes">
250             <props>
251                 <prop key="errors/error">500</prop>
252                 <prop key="errors/404">404</prop>
253             </props>
254         </property>
255         <!-- 设置日志输出级别,不定义则默认不输出警告等错误日志信息 -->
256         <property name="warnLogCategory">
257             <value>org.springframework.web.servlet.handler.SimpleMappingExceptionResolver
258             </value>
259         </property>
260         <!-- 默认错误页面,当找不到上面mappings中指定的异常对应视图时,使用本默认配置 -->
261         <property name="defaultErrorView" value="errors/error"></property>
262         <!-- 默认HTTP状态码 -->
263         <property name="defaultStatusCode" value="500"></property>
264     </bean>
265 
266 
267 </beans>

 

比较全的SpringMVC配置文件

标签:

原文地址:http://www.cnblogs.com/NapChen/p/5582075.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!