DefaultAdvisorAutoProxyCreator

DefaultAdvisorAutoProxyCreator
2008年04月25日 星期五 08:35
DefaultAdvisorAutoProxyCreator
-----------------------------------------------------------------------------------------------------------
package AutoProxyTwo;
public class Customer {
private String name;
private String id;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public Customer(String name, String id) {
super();
this.name = name;
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}

-----------------------------------------------------------------------------------------------------------
package AutoProxyTwo;
import StaticAdvisorTest.Shopping;
public class ShoppingImplA implements Shopping {
private Customer customer;
public Customer getCustomer() {
return customer;
}
public void setCustomer(Customer customer) {
this.customer = customer;
}
public String buySomething(String type) {
System.out.println(this.getCustomer().getName()
+ this.getCustomer().getId() + " 买 " + type + " success");
return null;
}
public String buyAnything(String type) {
System.out.println(this.getCustomer().getName() + " 买 " + type
+ " success");
return null;
}
public String sellAnything(String type) {
System.out.println(this.getCustomer().getName() + " sell " + type
+ " success");
return null;
}
public String sellSomething(String type) {
System.out.println(this.getCustomer().getName() + " sell " + type
+ " success");
return null;
}
}

-----------------------------------------------------------------------------------------------------------
package AutoProxyTwo;

import StaticAdvisorTest.Shopping;

public class ShoppingImplB implements Shopping {
private Customer customer;
public Customer getCustomer() {
return customer;
}
public void setCustomer(Customer customer) {
this.customer = customer;
}
public String buySomething(String type) {
System.out.println(this.getCustomer().getName()+" bye "+type+" success");
return null;
}

public String buyAnything(String type) {
System.out.println(this.getCustomer().getName()+" bye "+type+" success");
return null;

}
public String sellAnything(String type) {
System.out.println(this.getCustomer().getName()+" sell "+type+" success");
return null;
}
public String sellSomething(String type) {
System.out.println(this.getCustomer().getName()+" sell "+type+" success");
return null;
}

}
-----------------------------------------------------------------------------------------------------------
package AutoProxyTwo;
import java.io.File;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
import org.springframework.core.io.FileSystemResource;
import StaticAdvisorTest.Shopping;
public class TestAdvisor {
public static void main(String[] args) {
String filePath = System.getProperty("user.dir") + File.separator
+ "src" + File.separator + "applicationContext.xml";
System.out.println(filePath);
BeanFactory factory = new XmlBeanFactory(new FileSystemResource(
filePath));
ApplicationContext ctx = new FileSystemXmlApplicationContext(filePath);
Shopping shoppingA = null;
Shopping shoppingB = null;
shoppingA = (Shopping) ctx.getBean("buyBean");
shoppingB = (Shopping) ctx.getBean("sellBean");
shoppingA.buySomething("something");
shoppingA.buyAnything("anything");
shoppingB.sellAnything("anything");
shoppingB.sellSomething("something");
}
}



-----------------------------------------------------------------------------------------------------------
package AutoProxyTwo;

import java.lang.reflect.Method;

import org.springframework.aop.MethodBeforeAdvice;
//前置通知
public class WelcomeAdvice implements MethodBeforeAdvice {

public void before(Method method, Object[] args, Object obj)
throws Throwable {

System.out.println("Hello welcome to 买 ");

}

}
-----------------------------------------------------------------------------------------------------------
package StaticAdvisorTest;

public interface Shopping{
public String buySomething(String type);
public String buyAnything(String type);
public String sellSomething(String type);
public String sellAnything(String type);

}


-----------------------------------------------------------------------------------------------------------
<?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-2.0.xsd">

<bean ></bean>

<!-- 自动代理所有的advisor -->
<bean
>
</bean>


<bean
>
<property >
<value>.*sell.+</value><!-- 业务实现方法名匹配 -->
</property>
<property >
<ref bean="WelcomeAdvice" />
</property>
</bean>


<bean >
<property >
<ref bean="customer" />
</property>
</bean>
<bean >
<property >
<ref bean="customer" />
</property>
</bean>


<bean >
<constructor-arg index="0">
<value>熊熊</value>
</constructor-arg>
<constructor-arg index="1">
<value>66</value>
</constructor-arg>
</bean>
</beans>
-----------------------------------------------------------------------------------------------------------

本篇日志被作者设置为禁止发表新评论


©2008 Baidu



引文来源 DefaultAdvisorAutoProxyCreator_熊熊之家
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值