《Spring Recipes》第三章筆記1:Enabling AspectJ Annotation

《Spring Recipes》第三章筆記:Enabling AspectJ Annotation


問題


如何開啓Spring容器對AspectJ註解的支持。

解決方案


在配置文件中引入aop schema,添加<aop:aspectj-autoproxy />配置。

<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">

  <aop:aspectj-autoproxy />
... ...
</beans>

若是須要開啓CGLIB,則還須要將<aop:aspectj-autoproxy />元素的proxy-targetclass屬性設爲true。

Spring容器一旦發現配置文件中有<aop:aspectj-autoproxy />配置,則自動爲符合AspectJ 切面的bean建立代理。
相關文章
相關標籤/搜索