首页 > 代码库 > Spring AOP自动代理创建者
Spring AOP自动代理创建者
1. BeanNameAutoProxyCreator示例
<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-2.5.xsd"> <bean id="customerService" class=customer.services.CustomerService"> <property name="name" value="" /> <property name="url" value="www.baidu.com" /> </bean> <bean id="hijackAroundMethodBeanAdvice" class="com.yiibai.aop.HijackAroundMethod" /> <bean id="customerAdvisor" class="org.springframework.aop.support.NameMatchMethodYiibaicutAdvisor"> <property name="mappedName" value="printName" /> <property name="advice" ref="hijackAroundMethodBeanAdvice" /> </bean> <!-- BeanNameAutoProoxyCreator --> <bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator"> <property name="beanNames"> <list> <value>*Service</value> </list> </property> <property name="interceptorNames"> <list> <value>customerAdvisor</value> </list> </property> </bean> </beans>
2. DefaultAdvisorAutoProxyCreator示例
<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-2.5.xsd"> <bean id="customerService" class="customer.services.CustomerService"> <property name="name" value="xiaoming" /> <property name="url" value="www.baidu.com" /> </bean> <bean id="hijackAroundMethodBeanAdvice" class="aop.HijackAroundMethod" /> <bean id="customerAdvisor" class="org.springframework.aop.support.NameMatchMethodYiibaicutAdvisor"> <property name="mappedName" value="printName" /> <property name="advice" ref="hijackAroundMethodBeanAdvice" /> </bean> <bean class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator" /> </beans>
Spring AOP自动代理创建者
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。