我知道如何在Spring中配置简介aop
这是一种代码:
//my business serice
public class MyService {
public void doWork() {
System.out.println("doWork");
}
}
// the Introduction interface and its Implementation
public interface Someable {
public void method();
}
public class SomeImp implements Someable {
@Override
public void method() {
System.out.println("method");
}
}
春天的xml:
<aop:config proxy-target-class="true">
<aop:aspect id="TestAspect">
<aop:declare-parents types-matching="foo.bar.MyService+"
implement-interface="foo.bar.Someable"
default-impl="foo.bar.SomeImp"></aop:declare-parents>
</aop:aspect>
</aop:config>
然后是主要代码:
public class HelloApp {
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("spring-config.xml");
MyService myService = (MyService) context.getBean("myService");
myService.doWork();
((Someable) (myService)).method();
}
}
我想知道的是:
我可以在SomeImp课程中做什么,
哪种设计是我使用这个aop建议的方式,
我只是不明白使用AOP-Way
为服务添加接口的目的是什么有人可以在您的项目中应用一些真实的故事吗?