SpringMVC配置

来源:互联网 发布:守望先锋辅助网站源码 编辑:程序博客网 时间:2024/06/06 15:44
mvc-servlet.xml
<?xml version="1.0" encoding="UTF-8"?><beansxmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:p="http://www.springframework.org/schema/p"xmlns:context="http://www.springframework.org/schema/context"xmlns:tx="http://www.springframework.org/schema/tx"xmlns:aop="http://www.springframework.org/schema/aop"xmlns:mvc="http://www.springframework.org/schema/mvc"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsdhttp://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsdhttp://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.2.xsdhttp://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd"><!-- SpringMVC上传文件时,需要配置MultipartResolver处理器 --><bean id="multipartResolver"        class="org.springframework.web.multipart.commons.CommonsMultipartResolver">        <property name="defaultEncoding" value="UTF-8" />        <!-- 指定所上传文件的总大小,单位字节。注意maxUploadSize属性的限制不是针对单个文件,而是所有文件的容量之和 10M-->                <property name="maxUploadSize" value="10240000" />    </bean><!-- 扫描cn包中的所有类的注解 --><context:component-scan base-package="cn"></context:component-scan><!-- 所有文件默认由servlet控制 --><mvc:default-servlet-handler/><!-- MVC 控制层 交由Spring MVC拦截 --><mvc:annotation-driven/><!-- 从classpath类路径下加载properties配置文件 --><context:property-placeholder location="classpath:jdbc.properties"/><bean id="dataSource"          class="org.springframework.jdbc.datasource.DriverManagerDataSource">          <property name="driverClassName" value="${driverClass}" />      <property name="url" value="${url}"/>            <property name="username" value="${usernames}"/>          <property name="password" value="${password}" />      </bean>      <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">      <property name="dataSource" ref="dataSource"></property>    </bean>        <!-- 事务管理器,使用spring的事务控制 -->    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">         <property name="dataSource" ref="dataSource"></property>    </bean>   <!-- 定义通知 -->   <tx:advice id="myAdvise">   <tx:attributes>   <tx:method name="add*"/>   <tx:method name="remove*"/>   <tx:method name="update*"/>   <!-- 其它的方法只读,不开启事务 -->   <tx:method name="*" read-only="true"/>   </tx:attributes>   </tx:advice>   <aop:config>   <aop:pointcut expression="execution(* cn.*..*.service.*.*(..))" id="myPoint"/>   <aop:advisor advice-ref="myAdvise" pointcut-ref="myPoint"/>   </aop:config></beans>
 
原创粉丝点击