2
我嘗試AspectJ的@DeclareMixin
功能,但我不斷收到此錯誤:不能編譯AspectJ的看點與@DeclareMixin
/media/thomas/data-disk/sandbox/java/aspectj-tests/src/main/java/org/myproject/aspects/MyAspect.java:7:0::0 Method 'org.myproject.aspects.MyInterface org.myproject.aspects.MyAspect.declareStuff()': factory method does not return something that implements 'org.myproject.aspects.MyInterface'
這裏是我的方面:
package org.myproject.aspects;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.DeclareMixin;
@Aspect
public class MyAspect
{
@DeclareMixin(value = "@org.myproject.aspects.Marker *",
interfaces = MyInterface.class)
public MyInterface declareStuff()
{
return new MyImplementation();
}
}
這裏的註釋:
package org.myproject.aspects;
public @interface Marker
{
}
這裏的接口:
package org.myproject.aspects;
public interface MyInterface
{
public void doSomething();
}
這裏的實現:
package org.myproject.aspects;
public class MyImplementation implements MyInterface
{
@Override
public void doSomething()
{
System.out.println("Hello, world!");
}
}
這裏的POM:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>aspectj-tests</groupId>
<artifactId>aspectj-tests</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<aspectj-version>1.7.4</aspectj-version>
</properties>
<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>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.6</version>
<configuration>
<complianceLevel>1.7</complianceLevel>
<showWeaveInfo>true</showWeaveInfo>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>