<?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:context="http://www.springframework.org/schema/context" xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jpa="http://www.springframework.org/schema/data/jpa" xmlns:util="http://www.springframework.org/schema/util" 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.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.2.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.3.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd">
<context:component-scan base-package="com.tarena"/>
<mvc:annotation-driven/>
<!-- 拦截器配置 -->
<mvc:interceptors>
<!-- <mvc:interceptor>
<mvc:mapping path="/**" />
<bean
class="com.tarena.web.DemoInterceptor" />
</mvc:interceptor> -->
<!-- 授权拦截器: 任何请求都拦截, 除了/login路径
以下的请求不拦截
/demo/hello.form 请求被拦截, 如果: 当前会话中
已经有登录用户信息(用户已经登录) 拦截会允许继续
访问, 否则没有登录信息, 拦截或转发到 登录页面
-->
<mvc:interceptor>
<mvc:mapping path="/**"/>
<mvc:exclude-mapping path="/login/**"/>
<mvc:exclude-mapping path="/login2/**"/>
<bean class="com.tarena.web.AccessIntercept"/>
</mvc:interceptor>
</mvc:interceptors>
<bean id="handlerMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings" ref="mappings"/>
</bean>
<util:properties id="mappings">
<prop key="/hello.form">
helloController
</prop>
</util:properties>
<!-- 视图处理器 -->
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/"/>
<property name="suffix" value=".jsp"/>
</bean>
<util:properties id="jdbcProps" location="classpath:jdbc.properties"/>
<bean id="expHandler" class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
<!-- setExceptionMappings(Properties map) -->
<property name="exceptionMappings">
<props>
<!-- 如果出现空指针异常, 转发到
error.jsp -->
<prop key="java.lang.NullPointerException">
error
</prop>
</props>
</property>
</bean>
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="maxUploadSize" value="102400"/>
</bean>
<bean id="dbcpDataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="#{jdbcProps.driver}"/>
<property name="url" value="#{jdbcProps.url}"/>
<property name="username" value="#{jdbcProps.user}"/>
<property name="password" value="#{jdbcProps.pwd}"/>
<property name="initialSize" value="#{jdbcProps.init}"/>
<property name="maxActive" value="#{jdbcProps.max}"/>
<property name="maxIdle" value="#{jdbcProps.min}"/>
</bean>
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<!-- jdbcTemplate上有setDataSource()方法
setDataSource(DataSource d) 接口类型参数
可以注入任何DataSource 实现类即可 -->
<property name="dataSource" ref="dbcpDataSource"/>
<!-- 可以更换 c3p0 作为dataSource -->
</bean>
</beans>