madhava (2) [Avatar] Offline
#1
Ramnivas,

Referring to the listing 2.9 and the description surrounding using spring's aop:aspectj-autoproxy:
I used spring-2.5.6 and just created one aspect, one interface and one implementation class. Then I declared a bean that is of implementation class type. When I get the bean in a main() method using getbean() of ApplicationContext, i get the 'aspected' version. Note that i have NOT specified the aop:aspectj-autoproxy tag or any bean that of the aspect type.
What gives?

-Madhav
madhava (2) [Avatar] Offline
#2
Re: aspectj-autoproxy
One more thing: I'm using Eclipse with AJDT, and aspectjrt.jar is in the classpath along with spring-2.5.6.jar.

Perhaps presence of aspect in the classpath is sufficient for the implementation class to get aspected?

public aspect TracingAspect {
pointcut captureimpl() : execution(void ServiceInterface+.service*(..));
before() : captureimpl() {
System.out.println("TracingAspect.before() ServiceInterface+.service");
}
}

public class ServiceDefaultImpl implements ServiceInterface {
public void service(String name) {
System.out.println("ServiceDefaultImpl.service() with " + name);
}
}

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" >
xmlnssmiliesi="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.5.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
<!--<aop:aspectj-autoproxy /> -->
<bean id="defaultImpl" class="com.madhav.aspects.service.impl.ServiceDefaultImpl" />
</beans>

public class AspectTester {

public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext(new String[]{"springContext.xml"});
ServiceInterface interfaced = (ServiceInterface)context.getBean("defaultImpl");
interfaced.service("using spring context");
}
}
ramnivas (171) [Avatar] Offline
#3
Re: aspectj-autoproxy
Yes, if the project is an AspectJ project, AJDT will weave the aspects. Spring's <aop:aspectj-autoproxy> is needed only when you want to enable proxy-based weaving.

-Ramnivas