I just tried, and it worked the first time. Amazing :-) I've not been using @Configurable before because of the java-agent that I thought was required, didn't realize that it was this simple to get it working without the agent...
I just added a test to my existing setup. Posting the parts that may be relevant.
In my pom.xml inside build and <plugins> I have this:
Code:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<configuration>
<verbose>true</verbose>
<complianceLevel>1.5</complianceLevel>
<source>1.5</source>
<showWeaveInfo>true</showWeaveInfo>
<outxml>true</outxml>
<aspectLibraries>
<aspectLibrary>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
</aspectLibrary>
</aspectLibraries>
<includes>
<include>**/Property.java</include>
</includes>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
Inside pom.xml <dependencies> I have this:
Code:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>2.0</version>
</dependency>
My domain object (Also mapped by hibernate JPA, but ignore that part. It's @Configurable and the message String with setter thats important):
Code:
package se.lantmateriet.elips.poc.domain.model;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.OneToMany;
import javax.persistence.Transient;
import org.springframework.beans.factory.annotation.Configurable;
@Configurable
@Entity
public class Property extends AbstractDomainEntity {
@Transient
private String message;
@OneToMany(mappedBy="property", cascade=CascadeType.ALL)
private Set<Parcel> parcels;
public Property(UUID objectId, Integer objectVersion) {
super(objectId, objectVersion);
this.parcels = new HashSet<Parcel>();
}
private Property() {
super();
}
public void addParcel(Parcel parcel) {
parcel.setProperty(this);
this.parcels.add(parcel);
}
public void removeParcel(Parcel parcel) {
this.parcels.remove(parcel);
}
public Set<Parcel> getParcels() {
return this.parcels;
}
public String getMessage() {
return this.message;
}
public void setMessage(String message) {
this.message = message;
}
}
Spring config:
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:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:util="http://www.springframework.org/schema/util"
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
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-2.0.xsd"
default-autowire="no">
<aop:spring-configured/>
<bean id="helloWorld" class="java.lang.String">
<constructor-arg>
<value>Hello World</value>
</constructor-arg>
</bean>
<bean class="se.lantmateriet.elips.poc.domain.model.Property" scope="property">
<property name="message" ref="helloWorld"/>
</bean>
</beans>
And testcase:
Code:
package se.lantmateriet.elips.poc.domain.model;
import java.util.UUID;
import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
public class DomainInjectionTest extends
AbstractDependencyInjectionSpringContextTests {
@Override
protected String[] getConfigLocations() {
return new String[] { "classpath*:META-INF/spring-config/**/domain.xml" };
}
public void testInjection() {
Property property = new Property(UUID.randomUUID(), 0);
assertEquals("Hello World", property.getMessage());
logger.debug(property.getMessage());
}
}
Hope this helps. No output is made from the weaving, but it does weave.
/Magnus Heino