1. Manual generating agent
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
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.xsd">
<! - the target class configuration ============ ->
<the bean ID = "customerDao" = class "com.imooc.aop.demo4.CustomerDao" />
<!--配置通知============== -->
<bean id="myAroundAdvice" class="com.imooc.aop.demo4.MyAroundAdvice"/>
<! - general section using a section of the notice, due to the enhanced method for a target class you need to configure a section with an entry point ->
<bean the above mentioned id = "myAdvisor" class = "ORG. springframework.aop.support.RegexpMethodPointcutAdvisor ">
! <- configured in a regular expression pattern: any character * any number of times ->.
<- <Property name =!" pattern "value =" * the Save * "/.. > ->
<Property name = "Patterns" value =. "... * * Save, Delete * *" />
<Property name = "the advice" REF = "myAroundAdvice" />
</ the bean>
<!-- 配置产生代理 -->
<bean id="customerDaoProxy" class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="target" ref="customerDao"/>
<property name="proxyTargetClass" value="true"/>
<property name="interceptorNames" value="myAdvisor"/>
</bean>
</beans>
2. Based on the bean name is automatically generated proxy way
:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
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.xsd">
<!--配置目标类-->
<bean id="studentDao" class="com.imooc.aop.demo5.StudentDaoImpl"/>
<bean id="customerDao" class="com.imooc.aop.demo5.CustomerDao"/>
<!-- 配置增强-->
<bean id="myBeforeAdvice" class="com.imooc.aop.demo5.MyBeforeAdvice"/>
<bean id="myAroundAdvice" class="com.imooc.aop.demo5.MyAroundAdvice"/>
<bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
<property name="beanNames" value="*Dao"/>
<property name="interceptorNames" value="myBeforeAdvice"/>
</bean>
</beans>
3. The section information generated automatically Agent:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
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.xsd">
<!--配置目标类-->
<bean id="studentDao" class="com.imooc.aop.demo6.StudentDaoImpl"/>
<bean id="customerDao" class="com.imooc.aop.demo6.CustomerDao"/>
<!-- 配置增强-->
<bean id="myBeforeAdvice" class="com.imooc.aop.demo6.MyBeforeAdvice"/>
<bean id="myAroundAdvice" class="com.imooc.aop.demo6.MyAroundAdvice"/>
<!--配置切面-->
<bean id="myAdvisor" class="org.springframework.aop.support.RegexpMethodPointcutAdvisor">
<property name="pattern" value="com\.imooc\.aop\.demo6\.CustomerDao\.save"/>
<property name="advice" ref="myAroundAdvice"/>
</bean>
<bean class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator"></bean>
</beans>