--spring mvc -servlet.xml
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www./schema/beans" xmlns:xsi="http://www./2001/XMLSchema-instance" xmlns:p="http://www./schema/p" xmlns:context="http://www./schema/context" xsi:schemaLocation=" http://www./schema/beans http://www./schema/beans/spring-beans-3.0.xsd http://www./schema/context http://www./schema/context/spring-context-3.0.xsd http://www./schema/mvc http://www./schema/mvc/spring-mvc-3.0.xsd"> <!-- ①:对web包中的所有类进行扫描,以完成Bean创建和自动依赖注入的功能 --> <context:component-scan base-package="com.cqa.cms.controllers" /> <!-- spring的默认实现,不配置也一样 --> <bean id="handlerMapping" class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"> <property name="order" value="0" /> </bean> <bean id="jacksonMessageConverter" class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"> </bean> <bean id="hostUserArgumentResolver" class="com.cqa.cms.resolvers.HostUserArgumentResolver"/> <!-- ②:启动Spring MVC的注解功能,完成请求和注解POJO的映射 --> <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"> <property name="customArgumentResolver" ref="hostUserArgumentResolver" /> <property name="messageConverters"> <list> <ref bean="jacksonMessageConverter" /> </list> </property> </bean> <!-- ③:对模型视图名称的解析,即在模型视图名称添加前后缀 --> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" p:prefix="/WEB-INF/jsp/" p:suffix=".jsp" /> <!-- <bean name="viewResolver" class="org.springframework.web.servlet.view.XmlViewResolver" /> --> <bean id="exceptionResolver" class="com.cqa.cms.resolvers.TestExceptionResolver"> <property name="defaultErrorView"> <value>/common/500</value> </property> <property name="exceptionMappings"> <props> <prop key="java.lang.Exception">/common/500</prop> </props> </property> <property name="warnLogCategory" value="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver"></property> <property name="defaultStatusCode" value="500"></property> </bean> <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver" > <property name="defaultEncoding" value="UTF-8"/> <!-- 默认编码 (ISO-8859-1) --> <property name="maxInMemorySize" value="10240"/> <!-- 最大内存大小 (10240)--> <property name="uploadTempDir" value="/upload/"/> <!-- 上传后的目录名 (WebUtils#TEMP_DIR_CONTEXT_ATTRIBUTE) --> <property name="maxUploadSize" value="-1"/> <!-- 最大文件大小,-1为无限止(-1) --> </bean> </beans> interceptor-servlet.xml
<?xml version="1.0" encoding="UTF-8"?> <beans default-autowire="byName" xmlns="http://www./schema/beans" xmlns:xsi="http://www./2001/XMLSchema-instance" xmlns:p="http://www./schema/p" xmlns:mvc="http://www./schema/mvc" xmlns:util="http:///schma/util" xmlns:context="http://www./schema/context" xsi:schemaLocation=" http://www./schema/beans http://www./schema/beans/spring-beans-3.0.xsd http://www./schema/context http://www./schema/context/spring-context-3.0.xsd http://www./schema/mvc http://www./schema/mvc/spring-mvc-3.0.xsd http://www./schema/util http://www./schema/util/spring-util-3.0.xsd"> <mvc:interceptors> <mvc:interceptor> <mvc:mapping path="/**" /> <bean class="com.cqa.cms.interceptors.LogInterceptor" /> </mvc:interceptor> <mvc:interceptor> <mvc:mapping path="/admin/*" /> <bean class="com.cqa.cms.interceptors.AuthorizeInterceptor" /> </mvc:interceptor> <mvc:interceptor> <mvc:mapping path="/**" /> <bean class="com.cqa.cms.interceptors.DefaultViewInterceptor" /> </mvc:interceptor> </mvc:interceptors> <mvc:resources location="/jslib/**" mapping="/jslib/**"/> </beans> views.xml
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www./schema/beans" xmlns:xsi="http://www./2001/XMLSchema-instance" xmlns:aop="http://www./schema/aop" xmlns:tx="http://www./schema/tx" xsi:schemaLocation="http://www./schema/beans http://www./schema/beans/spring-beans-3.0.xsd http://www./schema/aop http://www./schema/aop/spring-aop-3.0.xsd http://www./schema/tx http://www./schema/tx/spring-tx-3.0.xsd" default-autowire="byName" default-lazy-init="true"> <bean name="jsonView" class="org.springframework.web.servlet.view.json.MappingJacksonJsonView" /> </beans> applicationContext-transaction.xml
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www./schema/beans" xmlns:xsi="http://www./2001/XMLSchema-instance" xmlns:aop="http://www./schema/aop" xmlns:tx="http://www./schema/tx" xsi:schemaLocation="http://www./schema/beans http://www./schema/beans/spring-beans-3.0.xsd http://www./schema/aop http://www./schema/aop/spring-aop-3.0.xsd http://www./schema/tx http://www./schema/tx/spring-tx-3.0.xsd" default-autowire="byName" default-lazy-init="true"> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource"/> </bean> <tx:advice id="txAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="add*" propagation="REQUIRED" rollback-for="Exception"/> <tx:method name="delete*" propagation="REQUIRED" rollback-for="Exception"/> <tx:method name="update*" propagation="REQUIRED" rollback-for="Exception"/> <tx:method name="save*" propagation="REQUIRED" rollback-for="Exception"/> <tx:method name="*" read-only="true" /> </tx:attributes> </tx:advice> <aop:config> <aop:pointcut id="serviceManager" expression="execution(* com.cqa.cms.service.impl.*Impl.*(..))"/> <aop:advisor advice-ref="txAdvice" pointcut-ref="serviceManager"/> </aop:config> </beans> |
|
来自: rui5327 > 《springmvc》