我是aspectJ的新手。我在 Aspect 类中遇到编译错误。运行项目时,出现编译错误。请帮我。放置下面得到的代码片段和错误:
项目结构:
MannersAspect.java
package main.java.testaop;
public aspect MannersAspect {
pointcut callSayMessage() :
call(public static void HelloWorld.say*(..));
before() : callSayMessage() {
System.out.println("Good day!");
}
after() : callSayMessage() {
System.out.println("Thank you!");
}
}
HelloWorld.java
package main.java.testaop;
public class HelloWorld {
public static void say(String message) {
System.out.println(message);
}
public static void sayToPerson(String message, String name) {
System.out.println(name + ", " + message);
}
}
pom.xml
<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>com.test</groupId>
<artifactId>testaop</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>testaop</name>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.8.4</version>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<versionRange>[2.5.1,)</versionRange>
<goals><goal>compile</goal></goals>
</pluginExecutionFilter>
<action><ignore></ignore></action>
</pluginExecution>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<versionRange>[1.7,)</versionRange>
<goals><goal>compile</goal></goals>
</pluginExecutionFilter>
<action><ignore></ignore></action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<executions>
<execution>
<goals><goal>compile</goal></goals>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution><goals><goal>java</goal></goals></execution>
</executions>
<configuration>
<mainClass>main.java.testaop.HelloWorld</mainClass>
</configuration>
</plugin>
</plugins>
</build>
</project>
错误:
[ERROR] COMPILATION ERROR :
[ERROR] D:\workspacedummy\testaop\src\main\java\testaop\MannersAspect.java:[3,7] error: class, interface, or enum expected
[ERROR] D:\workspacedummy\testaop\src\main\java\testaop\MannersAspect.java:[4,51] error: class, interface, or enum expected
[ERROR] D:\workspacedummy\testaop\src\main\java\testaop\MannersAspect.java:[4,72] error: malformed floating point literal
[ERROR] D:\workspacedummy\testaop\src\main\java\testaop\MannersAspect.java:[5,4] error: class, interface, or enum expected
[ERROR] D:\workspacedummy\testaop\src\main\java\testaop\MannersAspect.java:[7,4] error: class, interface, or enum expected
[ERROR] D:\workspacedummy\testaop\src\main\java\testaop\MannersAspect.java:[10,4] error: class, interface, or enum expected
[INFO] 6 errors
[INFO] BUILD FAILURE
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.5.1:compile (default-compile) on project testaop: Compilation failure: Compilation failure: