Spring+SpringMVC企业快速开发架构搭建(3)

<?xml version="1.0" encoding="UTF-8"?>
<web-app>
 <display-name>Archetype Created Web Application</display-name>
 <error-page>
  <exception-type>java.lang.Throwable</exception-type>
  <location>/500.jsp</location>
 </error-page>
 <error-page>
  <error-code>500</error-code>
  <location>/500.jsp</location>
 </error-page>
 <error-page>
  <error-code>404</error-code>
  <location>/404.jsp</location>
 </error-page>
 <!-- 装载spring 父上下文 -->
 <listener>
  <listener-class>org.springframework.web.context.ContextLoaderListener
  </listener-class>
 </listener>
 <context-param>
  <param-name>contextConfigLocation</param-name>
  <param-value>classpath:applicationContext*.xml</param-value>
 </context-param>
  <listener>
        <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
    </listener>
 <!-- 支持MVC 装载子上下文 -->
 <servlet>
  <servlet-name>springMVC</servlet-name>
  <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  <init-param>
   <description>Spring MVC Configuration Location</description>
   <param-name>contextConfigLocation</param-name>
   <param-value>
    classpath:spring-*.xml
   </param-value>
  </init-param>
  <load-on-startup>1</load-on-startup>
 </servlet>
 <servlet-mapping>
  <servlet-name>springMVC</servlet-name>
  <url-pattern>*.do</url-pattern>
 </servlet-mapping>
 <filter>
  <filter-name>encode</filter-name>
  <filter-class>org.springframework.web.filter.DelegatingFilterProxy
  </filter-class>
 </filter>
 <filter-mapping>
  <filter-name>ssojcFilter</filter-name>
  <url-pattern>/*</url-pattern>
 </filter-mapping>
</web-app>

2、Spring上下文配置文件ApplicationContext.xml用于配置Spring的通用配置

Applicationcontext.xml代码

<?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"
 xsi:schemaLocation="http://www.springframework.org/schema/beans
 
 
 
 
 
 
  ">

<context:property-placeholder location="classpath:*.properties" />
 
 <!--dataSource-->
 <bean init-method="init" destroy-method="close">
  <!-- 基本属性 url、user、password -->
  <property value="${jdbc.url}" />
  <property value="${jdbc.userName}" />
  <property value="${jdbc.passWord}" />
  <!-- 配置初始化大小、最小、最大 -->
  <property value="${jdbc.initialSize}" />
  <property value="${jdbc.minIdle}" />
  <property value="maxIdle" />
  <property value="${jdbc.maxActive}" />
  <!-- 配置获取连接等待超时的时间 -->
  <property value="60000" />
  <!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 -->
  <property value="${jdbc.timeBetweenEvictionRunsMillis}" />
  <!-- 配置一个连接在池中最小生存的时间,单位是毫秒 -->
  <property value="${jdbc.minEvictableIdleTimeMillis}" />
  <property value="${jdbc.validationQuery}" />
  <property value="${jdbc.testWhileIdle}" />
  <property value="${jdbc.testOnBorrow}" />
  <property value="${jdbc.testOnReturn}" />
  <property value="${jdbc.filters}" />
 </bean>
 <!--daoSupport-->
 <bean>
  <property ref="dataSource"/>
 </bean>
 
    <bean id = "transactionManager">
     <property ref="dataSource" />
    </bean>
 
 <!-- 声明式事务配置 -->
 <tx:advice transaction-manager="transactionManager">
  <tx:attributes>
   <tx:method propagation="REQUIRED" rollback-for="Throwable, Exception, RuntimeException"/>
   <tx:method propagation="REQUIRED" rollback-for="Throwable, Exception, RuntimeException"/>
   <tx:method propagation="REQUIRED" rollback-for="Throwable, Exception, RuntimeException"/>
   <tx:method propagation="REQUIRED" rollback-for="Throwable, Exception, RuntimeException"/>
   <tx:method propagation="REQUIRED" rollback-for="Throwable, Exception, RuntimeException"/>
   <tx:method propagation="REQUIRED" rollback-for="Throwable, Exception, RuntimeException"/>
   <tx:method propagation="REQUIRED" rollback-for="Throwable, Exception, RuntimeException"/>
   <tx:method propagation="REQUIRED" rollback-for="Throwable, Exception, RuntimeException"/>
   <tx:method propagation="NOT_SUPPORTED"/>
   <tx:method propagation="NOT_SUPPORTED"/>
   <tx:method propagation="NOT_SUPPORTED"/>
   <tx:method propagation="NOT_SUPPORTED"/>
   <tx:method read-only="true" propagation="SUPPORTS" />
  </tx:attributes>
 </tx:advice>
 <!-- 内部服务 -->
 <aop:config>
  <aop:pointcut expression="execution(* com.jl.net..service.*.*(..))" />
  <aop:advisor  pointcut-ref="pointCut" advice-ref="txAdvice"/>
 </aop:config>
 <!-- 对外服务 -->
 <aop:config>
  <aop:pointcut expression="execution(* com.jl.net..service.soa.*.*(..))" />
  <aop:advisor  pointcut-ref="pointCut_soa" advice-ref="txAdvice"/>
 </aop:config>
 <!-- JMS -->
 <aop:config>
  <aop:pointcut expression="execution(* com.jl.net..service.jms.receiver.*.*(..))" />
  <aop:advisor  pointcut-ref="pointCut_jms" advice-ref="txAdvice"/>
 </aop:config>

<!-- 定义过滤器 -->
 <bean>
  <property value="UTF-8" />
 </bean>
</beans>

3、SpringMVC配置

Springmmc.xml代码

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/5f1a66866c4382c54c46308843434311.html