1. 程式人生 > >ssm專案的一些配置檔案

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>