XML(2)——再看spring配置文件
一、前言之前寫過一篇《XML(1)——shema約束之命名空間》解釋了Schema中的命名空間,看過這篇文章之後會對Spring的配置文件有更好的理解。該文章地址:https://blog.csdn.net/woshixuye/article/details/26950075
二、再看Spring配置文件
spring.xml節選
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="https://www.springframework.org/schema/beans"
xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="https://www.springframework.org/schema/tx"
xmlns:aop="https://www.springframework.org/schema/aop"
xsi:schemaLocation="
https://www.springframework.org/schema/beans
https://www.springframework.org/schema/beans/spring-beans-3.0.xsd
https://www.springframework.org/schema/tx
https://www.springframework.org/schema/tx/spring-tx-3.0.xsd
https://www.springframework.org/schema/aop
https://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
<!-- 配置事務管理器 -->
<bean
>
<property name="dataSource" ref="dataSource" />
</bean>
<!-- 攔截器方式配置事務 -->
<tx:advice 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 expression="execution(* com.xy.service..*Impl.*(..))" />
<aop:advisor pointcut-ref="transactionPointcut" advice-ref="transactionAdvice" />
</aop:config>
</beans>
xmlns="https://www.springframework.org/schema/beans"該shema指定了整個spring文件默認約束,beans和bean標簽就在該約束下。
xmlns:tx和xmlns:aop指定了事務和麵向切麵的約束,所以這兩個約束下的標簽都是以tx或aop開頭的。
xmlns:xsi和xsi:schemaLocation還是指定了shema文件的位置,因為不是w3c的shema的話都需要指定該約束的位置。
最後更新:2017-04-03 20:19:26