一、前言
之前寫過一篇《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的話都需要指定該限制的位置。