XML(2)——再看spring配置文件

一、前言
之前寫過一篇《XML(1)——shema約束之命名空間》解釋了Schema中的命名空間,看過這篇文章之後會對Spring的配置文件有更好的理解。該文章地址:http://blog.csdn.net/woshixuye/article/details/26950075


二、再看Spring配置文件
spring.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: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-3.0.xsd 
http://www.springframework.org/schema/tx 
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/aop 
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">

<!-- 配置事務管理器 -->
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>

<!-- 攔截器方式配置事務 -->
<tx:advice id="transactionAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="*Tranc" propagation="REQUIRED" />
<tx:method name="*" read-only="true" />
</tx:attributes>
</tx:advice>
<!-- service包或子包裏,任意返回值(第一個*),任意以Impl結尾類(第二個*),任意方法(第三個*),方法可以含任意參數(..) -->
<aop:config>
<aop:pointcut id="transactionPointcut" expression="execution(* com.xy.service..*Impl.*(..))" />
<aop:advisor pointcut-ref="transactionPointcut" advice-ref="transactionAdvice" />
</aop:config>
</beans>
xmlns="http://www.springframework.org/schema/beans"該shema指定了整個spring文件默認約束,beans和bean標籤就在該約束下。
xmlns:tx和xmlns:aop指定了事務和麪向切面的約束,所以這兩個約束下的標籤都是以tx或aop開頭的。
xmlns:xsi和xsi:schemaLocation還是指定了shema文件的位置,因爲不是w3c的shema的話都需要指定該約束的位置。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章