Good Morning Everyone,
I am trying to get a simple aop app to work but it seems as if spring is ignoring the aop part of my spring-config file. Not sure what I'm doing wrong.
Here is what I have:
1) A simple interface and implementing class
2) A pojo aspect class
3) A class to test it
4) My spring config.xml
I get output:Code:
//==========================================
package com.macdon.aop.logging.test;
public interface IService {
Object doSomething(String obj,int i);
void doException() throws Throwable;
}
//==========================================
package com.macdon.aop.logging.test;
public class ServiceImpl implements IService{
public Object doSomething(String obj, int i) {
System.err.println(obj + i);
return obj;
}
public void doException() throws Throwable {
throw new Exception("Thrown exception");
}
}
//==========================================
package com.macdon.aop.logging;
public class TestAspect {
public TestAspect() {}
public void foo() {
System.out.println("===== This got injected =====");
}
}
//==========================================
<?xml version='1.0' encoding='windows-1252'?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
<bean id="fooService" class="com.macdon.aop.logging.test.ServiceImpl" />
<bean id="testerid" class="com.macdon.aop.logging.TestAspect" />
<aop:config>
<aop:aspect ref="testerid">
<aop ointcut id="all" expression="execution(* *.*(..))" />
<aop:before method="foo" pointcut="execution(* *.*(..))" />
<aop:before method="foo" pointcut-ref="all"/>
<aop:after-returning method="foo" pointcut-ref="all" />
<aop:after-throwing method="foo" pointcut-ref="all" />
</aop:aspect>
</aop:config>
</beans>
Testing 123
java.lang.Exception: Thrown exception at com.macdon.aop.logging.test.ServiceImpl.doExceptio n(ServiceImpl.java:17)
at com.macdon.aop.logging.test.TestLogger.main(TestLo gger.java:19)
But no aop behavior.
Can someone please help?
Thanks so much.
Yeuker
