ssm项目的一些配置文件

常用的几个组件名称和作用。

  • 前端控制器(DispatcherServlet):用于接收请求,响应结果

  • 处理器映射器(HandlerMapping):根据请求的url查找Handler(三大核心组件之一)

  • 处理器适配器(HandlerAdapter):按照特定的规则去执行Handler(三大核心组件之一)

  • 处理器(Handler):编写Handler时按照HandlerAdapter的要求去做,这样适配器才可以去正确执行Handler

  • 视图解析器(View resolver):进行视图解析(三大核心组件之一)

  • 视图(View):包括jsp、pdf等

有几个主要的配置文件,先了解下每个配置文件的作用。

1. web.xml:当服务启动时首先会去加载web.xml这个资源文件,里面包括了对前端控制器、乱码问题等配置。

2.applicatonContext.xml : 一般配置数据源,事物,注解 等。

在这里我使用的是applicatonContext-*.xml的形式将DAO、Service、Transaction层分开配置,这样便于管理

分别为applicatonContext-dao.xml、applicatonContext-service.xml、applicatonContext-transaction.xml

分开配置时,需要在web.xml中配置上下文位置

3.springmvc.xml: 里面配置的是控制层的 ,如视图解析器静态资源, mvc 文件上传,拦截器等。

4.SqlMapConfig.xml: 该配置文件为MyBatis的配置文件,里面无需配置,一切交给spring管理,但是xml文件基础配置要有。

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns="http://java.sun.com/xml/ns/javaee"
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
	id="WebApp_ID" version="2.5">
	<display-name>ssm_boot_crm</display-name>
	<welcome-file-list>
		<welcome-file>index.html</welcome-file>
		<welcome-file>index.htm</welcome-file>
		<welcome-file>index.jsp</welcome-file>
		<welcome-file>default.html</welcome-file>
		<welcome-file>default.htm</welcome-file>
		<welcome-file>default.jsp</welcome-file>
	</welcome-file-list>
	<!-- 上下文的位置 -->
	<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>classpath:applicationContext-*.xml</param-value>
	</context-param>
	<!-- Spring的监听器 -->
	<listener>
		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
	</listener>
 
 
	<!-- POST提交过滤器 UTF-8 -->
	<filter>
		<filter-name>encoding</filter-name>
		<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
		<init-param>
			<param-name>encoding</param-name>
			<param-value>UTF-8</param-value>
		</init-param>
	</filter>
 
	<filter-mapping>
		<filter-name>encoding</filter-name>
		<url-pattern>*.action</url-pattern>
	</filter-mapping>
	<!-- 前端控制器 -->
	<servlet>
		<servlet-name>crm</servlet-name>
		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
		<init-param>
			<param-name>contextConfigLocation</param-name>
			<!-- 此处不配置 默认找 /WEB-INF/[servlet-name]-servlet.xml -->
			<param-value>classpath:springmvc.xml</param-value>
		</init-param>
		<load-on-startup>1</load-on-startup>
	</servlet>
	<servlet-mapping>
		<servlet-name>crm</servlet-name>
		<!-- 1:*.do *.action 拦截以.do结尾的请求 (不拦截 jsp png jpg .js .css) 
		2:/ 拦截所有请求 (不拦截.jsp) 建议使用此种 方式 (拦截 .js.css .png) (放行静态资源) 
		3:/* 拦截所有请求(包括.jsp) 此种方式 不建议使用 -->
		<url-pattern>*.action</url-pattern>
	</servlet-mapping>
</web-app>

applicationContext-dao.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:mvc="http://www.springframework.org/schema/mvc"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
	xmlns:task="http://www.springframework.org/schema/task" xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
	xsi:schemaLocation="http://www.springframework.org/schema/beans 
		http://www.springframework.org/schema/beans/spring-beans-4.0.xsd 
		http://www.springframework.org/schema/mvc 
		http://www.springframework.org/schema/mvc/spring-mvc-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/aop 
		http://www.springframework.org/schema/aop/spring-aop-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/task
   		http://www.springframework.org/schema/task/spring-task-4.0.xsd
		http://code.alibabatech.com/schema/dubbo        
		http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
 
	<!-- srping框架 配置文件 用于管理数据库连接池 -->
	<!-- 配置 读取properties文件 db.properties -->
	<context:property-placeholder location="classpath:db.properties" />
 
	<!-- 配置 数据源 用于连接数据库 -->
	<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
		<!-- 数据库驱动 -->
		<property name="driverClassName" value="${jdbc.driver}" />
		<!-- 连接地址 -->
		<property name="url" value="${jdbc.url}" />
		<!-- 用户名 -->
		<property name="username" value="${jdbc.username}" />
		<!-- 密码 -->
		<property name="password" value="${jdbc.password}" />
 
	</bean>
	<!-- 配置 Mybatis的工厂 -->
	<bean class="org.mybatis.spring.SqlSessionFactoryBean">
		<!-- 绑定数据源 -->
		<property name="dataSource" ref="dataSource" />
		<!-- 配置Mybatis的核心 配置文件所在位置 -->
		<property name="configLocation" value="classpath:SqlMapConfig.xml" />
		<!-- 配置pojo别名 -->
		<property name="typeAliasesPackage" value="com.company.ssm.crm.pojo" />
	</bean>
	
	<!-- 配置  1:原始Dao开发 接口实现类 Mapper.xml 三个 
			 2:接口开发 接口 不写实现类 Mapper.xml 二个 (UserDao、ProductDao 
		、BrandDao。。。。。。。)
			 3:接口开发、并支持扫描 cn.itcast.core.dao(UserDao。) 写在此包下即可被扫描到 
	-->
	<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
		<property name="basePackage" value="com.company.ssm.crm.dao" />
	</bean>
	
</beans>

applicationContext-service.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:mvc="http://www.springframework.org/schema/mvc"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
	xmlns:task="http://www.springframework.org/schema/task" xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
	xsi:schemaLocation="http://www.springframework.org/schema/beans 
		http://www.springframework.org/schema/beans/spring-beans-4.0.xsd 
		http://www.springframework.org/schema/mvc 
		http://www.springframework.org/schema/mvc/spring-mvc-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/aop 
		http://www.springframework.org/schema/aop/spring-aop-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/task
   		http://www.springframework.org/schema/task/spring-task-4.0.xsd
		http://code.alibabatech.com/schema/dubbo        
		http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
 
 
	<!-- 配置扫描包 扫描 @Service    spring代理管理业务层 -->
	<context:component-scan base-package="com.company.ssm.crm.service" />
</beans>

applicationContext-transaction.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:context="http://www.springframework.org/schema/context" 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:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-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/aop http://www.springframework.org/schema/aop/spring-aop-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/util http://www.springframework.org/schema/util/spring-util-4.0.xsd">
 
 
	<!-- spring 事务管理器 -->
	<bean id="transactionManager"
		class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
		<!-- 数据源 -->
		<property name="dataSource" ref="dataSource" />
	</bean>
 
	<!-- 通知 -->
	<tx:advice id="txAdvice" transaction-manager="transactionManager">
		<tx:attributes>
			<!-- 传播行为 -->
			<tx:method name="save*" propagation="REQUIRED" />
			<tx:method name="insert*" propagation="REQUIRED" />
			<tx:method name="add*" propagation="REQUIRED" />
			<tx:method name="create*" propagation="REQUIRED" />
			<tx:method name="delete*" propagation="REQUIRED" />
			<tx:method name="update*" propagation="REQUIRED" />
			<tx:method name="find*" propagation="SUPPORTS" read-only="true" />
			<tx:method name="select*" propagation="SUPPORTS" read-only="true" />
			<tx:method name="get*" propagation="SUPPORTS" read-only="true" />
		</tx:attributes>
	</tx:advice>
	
	<!-- AOP 切面 -->
	<aop:config>
		<aop:advisor advice-ref="txAdvice"
			pointcut="execution(* cn.itcast.core.service.*.*(..))" />
	</aop:config>
	
</beans>

springmvc.xml

<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
	xmlns:task="http://www.springframework.org/schema/task" xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
	xsi:schemaLocation="http://www.springframework.org/schema/beans 
		http://www.springframework.org/schema/beans/spring-beans-4.0.xsd 
		http://www.springframework.org/schema/mvc 
		http://www.springframework.org/schema/mvc/spring-mvc-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/aop 
		http://www.springframework.org/schema/aop/spring-aop-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/task
   		http://www.springframework.org/schema/task/spring-task-4.0.xsd
		http://code.alibabatech.com/schema/dubbo        
		http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
 
	<!-- 加载属性文件 -->
	<context:property-placeholder location="classpath:resource.properties" />
	<!-- 配置扫描 器 -->
	<context:component-scan base-package="com.company.ssm.crm.controller" />
	<!-- 配置处理器映射器 适配器 -->
	<mvc:annotation-driven />
     
    <!--放行静态资源 -->
    <mvc:default-servlet-handler/>
    <bean id="multipartResolver"
          class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
        <!-- 上传文件大小上限,单位为字节(20MB) -->
        <property name="maxUploadSize">
            <value>20485760</value>
        </property>
        <!-- 请求的编码格式,必须和jSP的pageEncoding属性一致,以便正确读取表单的内容,默认为ISO-8859-1 -->
        <property name="defaultEncoding">
            <value>UTF-8</value>
        </property>
    </bean>
	
    <!-- 配置视图解释器 jsp -->
	<bean id="jspViewResolver"
		class="org.springframework.web.servlet.view.InternalResourceViewResolver">
		<property name="prefix" value="/WEB-INF/jsp/" />
		<property name="suffix" value=".jsp" />
	</bean>
 
</beans>

db.properties

jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/***?characterEncoding=utf-8
jdbc.username=root
jdbc.password=password

redisconfig.properties

redis.host=101.200.59.143//ip
redis.port=6379//端口
redis.password=237912
redis.maxIdle=300
redis.maxActive=600
redis.maxWait=10000
redis.testOnBorrow=true

spring-dubboconsumer.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:dubbo="http://code.alibabatech.com/schema/dubbo"

       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">

    <!--服务消费者-->
    <!--1、应用名称-->
    <dubbo:application name="newsconsumer"></dubbo:application>
    <!--2、配置注册中心-->
    <dubbo:registry address="zookeeper://10.8.163.82:2181" check="false"></dubbo:registry>
    <!--3、配置协议-->
    <dubbo:protocol name="dubbo" port="20882"  ></dubbo:protocol>
    <!--4、配置消费服务-->
    <dubbo:reference interface="com.qfedu.newhorizon.service.news.NewsService" id="newsServiceProvider" retries="0" timeout="20000"></dubbo:reference>
</beans>

spring-activemq.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:context="http://www.springframework.org/schema/context" xmlns:amq="http://activemq.apache.org/schema/core"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd">

    <context:property-placeholder location="classpath:activemq.properties"></context:property-placeholder>

    <!--2、连接工厂-->
    <amq:connectionFactory id="amqconnectionFactory" brokerURL="${activemq.url}" userName="${activemq.name}" password="${activemq.pass}"></amq:connectionFactory>
    <!--3、配置连接池-->
    <bean id="connectionFactory" class="org.springframework.jms.connection.CachingConnectionFactory">
        <property name="targetConnectionFactory" ref="amqconnectionFactory"></property>
        <property name="sessionCacheSize" value="1000"></property>
    </bean>
    <!--4、定义队列-->
    <bean id="newsqueue" class="org.apache.activemq.command.ActiveMQQueue">
        <constructor-arg name="name" value="newsmsg"></constructor-arg>
    </bean>

    <bean id="msgListener" class="com.qfedu.newhorizon.mq.news.NewsMQListener">
        <constructor-arg name="ns" ref="newsServiceProvider"></constructor-arg>
    </bean>

    <bean id="defaultMessageListenerContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
        <property name="connectionFactory" ref="connectionFactory"></property>
        <property name="destination" ref="newsqueue"></property>
        <property name="messageListener" ref="msgListener"></property>
    </bean>

</beans>

spring-activemq.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:context="http://www.springframework.org/schema/context" xmlns:amq="http://activemq.apache.org/schema/core"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd">

    <context:property-placeholder location="classpath:activemqconfig.properties"></context:property-placeholder>

    <!--2、连接工厂-->
    <amq:connectionFactory id="amqconnectionFactory" brokerURL="${activemq.url}" userName="${activemq.name}" password="${activemq.pass}"></amq:connectionFactory>
    <!--3、配置连接池-->
    <bean id="connectionFactory" class="org.springframework.jms.connection.CachingConnectionFactory">
        <property name="targetConnectionFactory" ref="amqconnectionFactory"></property>
        <property name="sessionCacheSize" value="1000"></property>
    </bean>
    <!--4、定义队列-->
    <bean id="newsqueue" class="org.apache.activemq.command.ActiveMQQueue">
        <constructor-arg name="name" value="newsmsg"></constructor-arg>
    </bean>
    <!--5、模板-->
    <bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
        <property name="connectionFactory" ref="connectionFactory"></property>
        <property name="defaultDestination" ref="newsqueue"></property>
        <property name="pubSubDomain" value="false"></property>
    </bean>

</beans>

spring-dao.xml

<?xml version="1.0" encoding="UTF-8"?>
<!--spring 的配置 约束文件用到哪个引入哪个 -->
<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"
       xsi:schemaLocation="
	http://www.springframework.org/schema/beans
		http://www.springframework.org/schema/beans/spring-beans.xsd
		http://www.springframework.org/schema/context
		http://www.springframework.org/schema/context/spring-context.xsd
		">

    <!--1、加载指定的配置文件 数据库的配置信息 -->
    <context:property-placeholder location="classpath:*config.properties" />
    <!--2、设置数据库连接池 -->
    <bean id="dataSource"
          class="com.alibaba.druid.pool.DruidDataSource">
        <property name="driverClassName" value="${dbdriver}"></property>
        <property name="url" value="${dburl}"></property>
        <property name="username" value="${dbusername}"></property>
        <property name="password" value="${dbpassword}"></property>
    </bean>

    <!--3、创建Mybatis的工厂对象 -->
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <!--设置数据库连接池 -->
        <property name="dataSource" ref="dataSource"></property>
    </bean>
    <!--4、设置Mybatis的映射文件的信息 -->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <!-- 设置映射文件所在包 -->
        <property name="basePackage" value="com.qfedu.newhorizon.mapper"></property>
    </bean>

</beans>

spring-dubboprovider.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:dubbo="http://code.alibabatech.com/schema/dubbo"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">

    <!--1、应用名称设置-->
    <dubbo:application name="newsprovider"></dubbo:application>
    <!--2、配置注册中心-->
    <dubbo:registry address="10.8.163.82:2181" protocol="zookeeper" check="false"></dubbo:registry>
    <!--3、设置协议-->
    <dubbo:protocol name="dubbo" port="20882"></dubbo:protocol>
    <!--4、设置发布的服务-->
    <dubbo:service interface="com.qfedu.newhorizon.service.news.NewsService" ref="newsServiceProvider" retries="0" timeout="20000"></dubbo:service>
</beans>

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

    <context:property-placeholder location="classpath:*config.properties" />

    <bean id="jedisConfig" class="redis.clients.jedis.JedisPoolConfig">
        <property name="maxTotal" value="${redis.maxActive}"></property>
        <property name="maxIdle" value="${redis.maxIdle}"></property>
        <property name="maxWaitMillis" value="${redis.maxWait}"></property>
        <property name="testOnBorrow" value="${redis.testOnBorrow}"></property>
    </bean>
    <!-- 2、redis连接工厂 -->
    <bean id="connectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">
        <property name="hostName" value="${redis.host}"></property>
        <property name="port" value="${redis.port}"></property>
        <property name="password" value="${redis.password}"></property>
        <property name="poolConfig" ref="jedisConfig"></property>
    </bean>

    <!-- 3、redis操作模板,这里采用尽量面向对象的模板 -->
    <bean id="redisTemplate" class="org.springframework.data.redis.core.StringRedisTemplate">
        <property name="connectionFactory" ref="connectionFactory"/>
        <property name="keySerializer" >
            <bean class="org.springframework.data.redis.serializer.StringRedisSerializer" />
        </property>
        <property name="valueSerializer" >
            <bean class="org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer" />
        </property>
        <property name="hashKeySerializer">
            <bean class="org.springframework.data.redis.serializer.StringRedisSerializer"/>
        </property>
        <property name="hashValueSerializer">
            <bean class="org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer"/>
        </property>
        <!--开启事务-->
        <property name="enableTransactionSupport" value="true"/>
    </bean>
    <!--4、配置Redis的工具类,自定义-->
    <bean id="redisUtil" class="com.qfedu.newhorizon.common.redis.RedisUtil">
        <property name="redisTemplate" ref="redisTemplate"></property>
    </bean>
</beans>

spring-service.xml

<?xml version="1.0" encoding="UTF-8"?>
<!--spring 的配置 约束文件用到哪个引入哪个 -->
<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:tx="http://www.springframework.org/schema/tx"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xsi:schemaLocation="
	http://www.springframework.org/schema/beans
		http://www.springframework.org/schema/beans/spring-beans.xsd
		http://www.springframework.org/schema/context
		http://www.springframework.org/schema/context/spring-context.xsd
		http://www.springframework.org/schema/tx
		http://www.springframework.org/schema/tx/spring-tx.xsd
		http://www.springframework.org/schema/aop
		http://www.springframework.org/schema/aop/spring-aop.xsd
		">
    <context:component-scan base-package="com.qfedu.newhorizon.provider.news"></context:component-scan>
    <!--5、配置事务 -->
    <!--事务管理器 -->
    <bean id="transactionManager"
          class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <!--配置数据库连接池 需要为那些设置事务 -->
        <property name="dataSource" ref="dataSource"></property>
    </bean>
    <!--配置 增强处理类 -->
    <tx:advice transaction-manager="transactionManager"
               id="txadvice">
        <!--设置具体的方法的事务信息 -->
        <tx:attributes>
            <!--具体的方法 连接点 -->
            <tx:method name="save*" />
            <tx:method name="update*" />
            <tx:method name="del*" />
            <tx:method name="*" />
        </tx:attributes>
    </tx:advice>
    <!--配置aop -->
    <aop:config>
        <!--配置需要添加事务的方法 -->
        <aop:pointcut
                expression="execution(* com.qfedu.newhorizon.provider.news.NewsProvider.*.*(..))" id="tpt" />
        <!--设置事务 -->
        <aop:advisor advice-ref="txadvice" pointcut-ref="tpt" />
    </aop:config>

</beans>

猜你喜欢

转载自blog.csdn.net/LS1117/article/details/82982269