无法使用@DeclareMixin编译AspectJ方面

时间:2014-02-08 00:11:09

标签: java maven aspectj

我正在尝试AspectJ的@DeclareMixin功能,但我一直收到此错误:

  

/media/thomas/data-disk/sandbox/java/aspectj-tests/src/main/java/org/myproject/aspects/MyAspect.java:7:0::0方法'org.myproject.aspects。 MyInterface org.myproject.aspects.MyAspect.declareStuff()':工厂方法不返回实现'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>

1 个答案:

答案 0 :(得分:0)

我发现如果从interfaces注释中删除@DeclareMixin元素,它就可以了。