1

I'm using Spring in my current project, but the @Configurable annotation doesn't work.

I've used the annotation in some of my classes (most of them JPA Entities):

@Configurable  
@Entity  
public class Person{  
...  
  @Inject  
  private PersonService service;  
...  
}  

I've put the aspectj-maven plugin in my pom.xml:

<plugin>

<groupId>org.codehaus.mojo</groupId>  
<artifactId>aspectj-maven-plugin</artifactId>  
<version>1.4</version>
<dependencies> 
<dependency>  
<groupId>org.aspectj</groupId>  
<artifactId>aspectjrt</artifactId>  
<version>${aspectj.version}</version>  
</dependency>  
<dependency>  
<groupId>org.aspectj</groupId>  
<artifactId>aspectjtools</artifactId> 
<version>${aspectj.version}</version>  
</dependency>  
</dependencies>  
<executions>  
<execution>  
<phase>process-sources</phase>  
<goals>  
<goal>compile</goal>  
<goal>test-compile</goal>  
</goals>  
</execution>  
</executions>  
<configuration>  
<outxml>true</outxml>  
<showWeaveInfo>true</showWeaveInfo>  
<Xlint>ignore</Xlint>  
<aspectLibraries>  
<aspectLibrary>  
<groupId>org.springframework</groupId>  
<artifactId>spring-aspects</artifactId>  
</aspectLibrary>  
</aspectLibraries>  
<source>${java.version}</source>  
<target>${java.version}</target>  
<weaveWithAspectsInMainSourceFolder>false</weaveWithAspectsInMainSourceFolder>  
</configuration>  
</plugin>

But the Spring aspect is not loaded at compilation time, so the @Inject annotation doesn't work.

jfcorugedo
  • 9,793
  • 8
  • 39
  • 47

1 Answers1

1

The problem is the maven compilation version.

With version 2.5.1 the Spring aspect is loaded successfully:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-compiler-plugin</artifactId>
  <version>2.5.1</version>
  <configuration>
    <source>${java.version}</source>
    <target>${java.version}</target>
    <encoding>${project.build.sourceEncoding}</encoding>
  </configuration>
</plugin>

But with the version 3.1, the aspect does not work.

THIS DOES NOT WORK:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-compiler-plugin</artifactId>
  <version>3.1</version>
  <configuration>
    <source>${java.version}</source>
    <target>${java.version}</target>
    <encoding>${project.build.sourceEncoding}</encoding>
  </configuration>
</plugin>
jfcorugedo
  • 9,793
  • 8
  • 39
  • 47