Strange, i made it work a few months ago but now i can't get even a basic Aspect to work. No methods are ever intercepted, as if i had no AOP at all.
The configuration:
The aspect (the poincut seems alright)Code:<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" 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.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd"> <aop:aspectj-autoproxy/> <bean class="hellotrackworld.AspectTata"/> <context:component-scan base-package="hellotrackworld"/> <context:annotation-config/> </beans>
The bean that should be advised:Code:package hellotrackworld; import org.aspectj.lang.annotation.Before; import org.aspectj.lang.annotation.Pointcut; import org.jboss.aop.Aspect; @Aspect public class AspectTata { @Before ( "anyPublicOperation()" ) public void printTata () { System.out.println ( "!!!!!TATA!!!!!!" ); System.out.println ( "!!!!!TATA!!!!!!" ); System.out.println ( "!!!!!TATA!!!!!!" ); System.out.println ( "!!!!!TATA!!!!!!" ); System.out.println ( "!!!!!TATA!!!!!!" ); } @SuppressWarnings("unused") @Pointcut("execution(public * *(..))") private void anyPublicOperation() {} }
The test:Code:package hellotrackworld; import org.springframework.stereotype.Service; @Service("fooService") public class FooServiceImpl implements FooService { @Override public void foo() { System.out.println ( "foo" ); } }
Code:package hellotrackworld; import javax.annotation.Resource; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.aop.support.AopUtils; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration ( locations={"/resources/application-context.xml"} ) public class TestAOP { @Resource ( name="fooService" ) private FooService fooService; @Test public void toto () { boolean isAopProxy; isAopProxy = AopUtils.isAopProxy(fooService);//returns false System.out.println ( "______isAopProxy: " + isAopProxy ); fooService.foo();//no interception } }


Reply With Quote