PDA

View Full Version : Aspect not being applied to @Configurable



rjivan
Jul 5th, 2007, 04:45 PM
I am looking to migrate my code base from Spring 1.2.8 to Spring 2.0..6. I have a couple of hibernate beans that are being injected using DependencyInjectionInterceptorFactoryBean from the spring-sandbox. With 2.0.6 I've read that the recommend approach for domain object injection is via AspectJ. I have followed the following steps get Spring to inject in my domain object.

1. Created aop.xml in the META-INF directory



<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE aspectj PUBLIC
"-//AspectJ//DTD//EN" "http://www.eclipse.org/aspectj/dtd/aspectj.dtd">

<aspectj>
<weaver options="-showWeaveInfo -XmessageHandlerClass:org.springframework.aop.aspec tj.AspectJWeaverMessageHandler">
<include within="com.mycompany.domain..*" />
</weaver>

<aspects>
<include within="org.springframework.beans.factory.aspectj.Annotati onBeanConfigurerAspect"/>
</aspects>
</aspectj>


2. Added @Configurable annotation to my domain object


@Configurable
public class Test {
private Long id;
private String name;
private TestDAO testDAO;

//setter and getters
.....
}


3. Added the following entries in applicationContext.xml


<aop:spring-configured/>
<aop:aspectj-autoproxy/>
<bean id="testDAO class="TestDAO">
</bean>

<bean class="Test" scope="prototype">
<property name="testDAO" ref="testDAO"/>
</bean>


4, Added the jvm option -javaagent:c:\tomcat\common\lib\aspectjweaver.jar

What I startup up the application I see that the property testDAO in the class Test is null. What am I missing?

amin
Jul 10th, 2007, 08:24 AM
What is TestDao...is it an interface or concrete class? If it's an interface then u need to define the implementation class in the config file.

rjivan
Jul 11th, 2007, 11:08 AM
I have ditched the AOP approach. Instead used the approach outlined in
http://joesbitbucket.blogspot.com/2006/08/how-to-inject-dependencies-into-domain.html

Its a lot easier to setup and doesn't require any runtime or compile time dependencies on AspectJ.

Are there any disadvantages of using static method injection versus using @Configurable?