Spring MVC配置(备忘)
2015-09-01 14:22
453 查看
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd" > <!-- 默认的注解映射的支持:它会自动注册HandlerMapping、HandlerAdapter、ExceptionResolver的相关实例 --> <mvc:annotation-driven /> <!-- 自动扫描的包名 --> <!-- 扫描类包,将标注Spring注解的类自动转化Bean,同时完成Bean的注入 --> <context:component-scan base-package="com.chinagpay.abroad" /> <!-- 视图解释类 --> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/pages/"/> <property name="suffix" value=".jsp"/><!--可为空,方便实现自已的依据扩展名来选择视图解释类的逻辑 --> <property name="viewClass" value="org.springframework.web.servlet.view.JstlView" /> </bean> <!-- 国际化 --> <bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource"> <property name="basename" value="com.chinagpay.abroad.i18n.messages"/> <property name="defaultEncoding" value="utf-8"></property> </bean> <!-- 通过cookie获取本地语言,可通过XXX?locale=en_US或者zh_CH.自动切换语言。 --> <bean id="localeResolver" class="org.springframework.web.servlet.i18n.CookieLocaleResolver" /> <!-- 拦截器 --> <mvc:interceptors> <!-- 过滤用户是否登录 --> <mvc:interceptor> <mvc:mapping path="/user/**"/> <mvc:mapping path="/edu/**"/> <mvc:mapping path="/cross/**"/> <bean class="com.chinagpay.abroad.common.interceptors.LoginInterceptor" /> </mvc:interceptor> <!-- 防止表单重发提交 --> <mvc:interceptor> <mvc:mapping path="/user/**"/> <bean class="com.chinagpay.abroad.common.interceptors.TokenInterceptor" /> </mvc:interceptor> <!-- 过滤特殊字符 --> <mvc:interceptor> <mvc:mapping path="/**/**"/> <bean class="com.chinagpay.abroad.common.interceptors.ContentFilter" /> </mvc:interceptor> <!-- 国际化 --> <bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor" /> </mvc:interceptors> <!-- 对静态资源文件的访问 方案一 (二选一) --> <!--<mvc:default-servlet-handler/> --> <mvc:resources mapping="/images/**" location="/images/" cache-period="31556926"/> <mvc:resources mapping="/js/**" location="/js/" cache-period="31556926"/> <mvc:resources mapping="/css/**" location="/css/" cache-period="31556926"/> <mvc:resources mapping="/doc/**" location="/doc/" cache-period="31556926"/> <!-- 支持上传 --> <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver" > <property name="defaultEncoding" value="utf-8" /> </bean> <!-- 加载jdbc配置文件 --> <context:property-placeholder location="/WEB-INF/jdbc.properties" /> <!-- 数据源 ,DBCP连接池--> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName" value="${jdbc.driverClassName}"/> <property name="url" value="${jdbc.url}"/> <property name="username" value="${jdbc.username}"/> <property name="password" value="${jdbc.password}"/> <property name="initialSize" value="2"/> <property name="maxActive" value="10"/> <property name="maxIdle" value="10"/> <property name="maxWait" value="1000"/> <property name="poolPreparedStatements" value="true"/> </bean> <!-- 配置Jdbc模板 --> <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate"> <property name="dataSource" ref="dataSource"></property> </bean> <!-- 配置事务管理器 --> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource"></property> </bean> <!-- 用注解来实现事务管理 --> <tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true"/> <!-- dao注入 --> <!-- <bean id="userService" class="com.chinagpay.abroad.service.impl.UserServiceImpl"> <property name="jdbcTemplate" ref="jdbcTemplate"></property> </bean> --> </beans>
相关文章推荐
- spring MVC(十)---spring MVC整合mybatis
- spring MVC(十)---spring MVC整合mybatis
- SpringMVC+ajax返回JSON串
- ubuntu上面安装eclipse android到adt下载方法
- Java开发中的23种设计模式详解
- spring+springMvc 架构导致定时任务重复加载执行两次
- 怎样从SpringMVC返回json数据
- 登陆页面书写-工作第三天的任务
- Spring Data JPA
- 在eclipse查看androidandroid sdk源码
- java内存分配
- 10个实用的但偏执的Java编程技术-扣丁学堂
- 在eclipse查看android-support-v4.jar源码
- 10个实用的但偏执的Java编程技术
- springmvc 上传文件
- java异常处理
- Spring学习(九)使用ioc注解方式配置bean
- java变量的初始化
- spring路径(个人笔记)
- java反射机制