Spring @Configurable with Maven

时间:2013-10-06 21:34:25

标签: spring aspectj configurable

我在当前项目中使用Spring,但@Configurable注释不起作用。

我在我的一些课程中使用了注释(大多数是JPA实体):

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

我把aspectj-maven插件放在我的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>

但Spring方面没有在编译时加载,因此@Inject注释不起作用。

1 个答案:

答案 0 :(得分:1)

问题是maven编译版本。

使用2.5.1版本,Spring方面成功加载:

<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>

但是使用版本3.1,方面不起作用。

这不起作用:

<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>