dispatcher-servlet.xml 8.27 KB
<?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:p="http://www.springframework.org/schema/p"
    xmlns:aop="http://www.springframework.org/schema/aop"
    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-4.0.xsd
        http://www.springframework.org/schema/tx   
        http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
        http://www.springframework.org/schema/aop   
		http://www.springframework.org/schema/aop/spring-aop-4.0.xsd 
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-4.0.xsd
        http://www.springframework.org/schema/mvc    
        http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">
        

    <context:annotation-config />                                
	<context:property-placeholder location="classpath:config.properties" />  
    <context:component-scan base-package="com.bjivt.web.controller,com.bjivt.service,com.bjivt.dao,com.bjivt.base"></context:component-scan>   
    
    <mvc:interceptors>
        <mvc:interceptor>
            <mvc:mapping path="/**"/>
           <!-- 登录验证拦截器 -->
		<bean id="sessionInterceptor" class="com.bjivt.web.interceptor.SessionInterceptor">
			<!-- 登录地址 -->
			<property name="loginUrl" value="/managerLogin.html"></property>
			<!-- 验证session的名称 -->
			<property name="sessionName" value="manager"></property>
			<!-- 忽略地址列表,不拦截 -->
			<property name="ignoreList">
				<list>
					<value>/managerToLogin.html</value>
				</list>
			</property>
		</bean>
        </mvc:interceptor>
    </mvc:interceptors>

	<!-- 将多个配置文件读取到容器中,交给Spring管理 -->
	<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
		<property name="locations">
			<list>
				<value>classpath:config.properties</value>
			</list>
		</property>
	</bean>


	<bean  class="org.springframework.web.servlet.view.InternalResourceViewResolver">
		<property name="viewClass">
		<value>org.springframework.web.servlet.view.JstlView</value>
		</property>
		<property name="prefix">
		<value>/WEB-INF/views/jsp/</value>
		</property>
		<property name="suffix">
		<value>.jsp</value>
		</property>
	</bean>
	 <!-- redis setting start -->
	    <bean id="poolConfig" class="redis.clients.jedis.JedisPoolConfig">  
	        <property name="maxIdle" value="${redis.maxIdle}" />  
	        <property name="maxTotal" value="${redis.maxActive}" />  
	        <property name="maxWaitMillis" value="${redis.maxWait}" />  
	        <property name="testOnBorrow" value="${redis.testOnBorrow}" />  
	    </bean>  
	      
	    <bean id="connectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">  
	           <property name="hostName" value="${redis.host}" />  
		       <property name="port" value="${redis.port}" />  
		       <property name="password" value="${redis.pass}" />  
		       <property name="usePool" value="true" />  
		       <property name="poolConfig" ref="poolConfig" />  
       </bean>
	      
	    <bean id="redisTemplate" class="org.springframework.data.redis.core.StringRedisTemplate">  
	        <property name="connectionFactory"   ref="connectionFactory" />  
	    </bean>  
     <!-- redis setting end -->     
	<bean id="springContextUtil" class="com.bjivt.util.SpringContextUtil" />
	 <!-- bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"-->
	 <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" destroy-method="close">
		<!-- 基本属性 url、user、password -->
		<property name="url" value="jdbc:mysql://192.168.4.49/db_showtime_platform?characterEncoding=UTF-8&amp;SelectMethod=Cursor&amp;zeroDateTimeBehavior=convertToNull&amp;allowMultiQueries=true" />
		<property name="username" value="mijia" />
		<property name="password" value="bjivt_MIJIA" />
		<!-- 配置初始化大小、最小、最大 -->
		<property name="initialSize" value="1" />
		<property name="minIdle" value="1" />
		<property name="maxActive" value="20" />
		<!-- 配置获取连接等待超时的时间 -->
		<property name="maxWait" value="60000" />
		<!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 -->
		<property name="timeBetweenEvictionRunsMillis" value="60000" />
		<!-- 配置一个连接在池中最小生存的时间,单位是毫秒 -->
		<property name="minEvictableIdleTimeMillis" value="300000" />
		<property name="validationQuery" value="SELECT 'x'" />
		<property name="testWhileIdle" value="true" />
		<property name="testOnBorrow" value="false" />
		<property name="testOnReturn" value="false" />
		<!-- 打开PSCache,并且指定每个连接上PSCache的大小 -->
		<property name="poolPreparedStatements" value="true" />
		<property name="maxPoolPreparedStatementPerConnectionSize" value="20" />
		<!-- 配置监控统计拦截的filters -->
		<property name="filters" value="stat" />

        <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
            
	</bean>
	   <!-- 使用JDBC事物 -->  
	    <bean id="transactionManager"  
	        class="org.springframework.jdbc.datasource.DataSourceTransactionManager">  
	        <property name="dataSource" ref="dataSource" />  
	    </bean>  
		
	   <!-- AOP配置事物 -->  
	    <tx:advice id="transactionAdvice" transaction-manager="transactionManager">  
	        <tx:attributes>  
	            <tx:method name="query*" read-only="true" propagation="REQUIRED" />  
	            <tx:method name="delete*"  propagation="REQUIRED" />  
	            <tx:method name="update*" propagation="REQUIRED" />  
	            <tx:method name="insert*" propagation="REQUIRED" />  
	            <tx:method name="*" propagation="REQUIRED" />  
	        </tx:attributes>  
	    </tx:advice>  
	      
	    <!-- 配置AOP切面 -->  
	    <aop:config>                                                      
	        <aop:pointcut id="transactionPointcut" expression="execution(* com.bjivt.*.service.impl..*Impl.*(..)) || execution(* com.bjivt.*.data.service.impl..*Impl.*(..))"/>
	        <aop:advisor pointcut-ref="transactionPointcut" advice-ref="transactionAdvice"/>  
	    </aop:config>  
	  
	    <!-- 使用annotation注解方式配置事务 -->  
      <tx:annotation-driven transaction-manager="transactionManager" />   
	 
   <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">  
        <property name="dataSource" ref="dataSource" />  
        <property name="configLocation" value="classpath:mybatis-config.xml"></property>  
    </bean>  
  
    <!-- 配置SQLSession模板 -->  
    <bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate" scope="prototype">  
        <constructor-arg index="0" ref="sqlSessionFactory" />  
    </bean>  

    
	<bean id="mappingJacksonHttpMessageConverter" class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter" >
 	    <property name="supportedMediaTypes"> 
        <list>
        <value>application/json;charset=UTF-8</value>
       </list>
      </property>
	</bean>  
	 <bean class ="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" >  
        <property name="messageConverters">  
      <list>  
       <ref bean="mappingJacksonHttpMessageConverter" /><!-- json转换器 -->  
      </list>  
     </property>  
    </bean>
   <!--定义异常处理页面-->
<!--     <bean id="exceptionResolver" class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
        <property name="exceptionMappings">
            <props>
                <prop key="java.lang.Exception">/system/outException</prop>
            </props>
        </property>
    </bean> -->
    <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
    	<property name="maxUploadSize"><value>700000000</value></property>
    	<property name="defaultEncoding"><value>UTF-8</value></property>
    </bean>
</beans>