-
Jul 16th, 2007, 02:09 PM
#1
Creating a the poincut based on an interface declared through aop:declare-parents
I figured out how to make a service implement a new interface and provide some implementation for it. Every thing is working well on this side. I can inject my service in an other classes, cast it into my new interface and call the new interface's methods successfully. Later on, I tried to create an aspect to intercept calls made on my new interface's methods but I wasn't able to make it work.
Here is how I am setted:
public class Service1Impl implements Service1{
...
}
<bean id="service1" class="com.app.service.impl.Service1Impl">
<property name="dao1" ref="dao1" />
</bean>
<bean id="aspect1" class="com.app.aspect.Aspect1">
<property name="dao2" ref="dao2" />
</bean>
<aop:config>
<aop:aspect ref="aspect1">
<aop:declare-parents types-matching="com.app.service.impl.Service1Impl"
implement-interface="com.app.service.Interface1"
default-impl="com.app.service.impl.Interface1Impl"/>
<aop:before pointcut="this(com.app.service.Interface1)" method="aspect1Method1"/>
</aop:aspect>
</aop:config>
public class TestClass extends AbstractTransactionalDataSourceSpringContextTests{
private Service1 service1;
public TestClass(String name) {
super(name);
}
public static void main(String args[]) {
TestRunner.run(new TestSuite(TestClass.class));
}
public void testService1Interface1(){
Interface1 service1Interface1 = (Interface1) this.service1;
service1Interface1.method();
}
...
}
This way, methods in Interface1Impl get called, but not the method Aspect1.aspect1Method1(). Should it be working or not? If I change my pointcut to the match implementors of com.app.service.Service1, it work without any problem.
<aop:config>
<aop:aspect ref="aspect1">
<aop:declare-parents types-matching="com.app.service.impl.Service1Impl"
implement-interface="com.app.service.Interface1"
default-impl="com.app.service.impl.Interface1Impl"/>
<aop:before pointcut="this(com.app.service.Service1)" method="aspect1Method1"/>
</aop:aspect>
</aop:config>
Thank you.
-
Jul 20th, 2007, 03:56 AM
#2
try putting all your bean conf. into single xml file. it may work, not sure though...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules