私はmaven Java EE 6プロジェクトを持っており、すべてのメソッドに、ロガー情報をコンソールに表示し、パラメータで始まり、最後も持っています。
一部のメソッドでは、make を忘れていたので、呼び出されたすべてのメソッドの開始と終了を管理するために、aspectJ を使用したいと考えています。
Jboss EAP6 をサーバーとして使用し、Jboss developerper Studio を IDE として使用しています。ネットでいくつかのチュートリアルを見つけましたが、常に spring または java aspactJ プロジェクトについて話しています。IDEにプラグインaspectJをインストールしましたが、MavenプロジェクトがaspectJプロジェクトではないというアスペクトを追加しようとしましたが、どうすれば解決できますか?
これは私のmaven pom.xml
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.7.3</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.7.3</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>snapshots</id>
<name>repo1-maven</name>
<url>http://central.maven.org/maven2</url>
</repository>
<repository>
<id>JBoss repository</id>
<url>http://repository.jboss.org/nexus/content/groups/public/</url>
</repository>
</repositories>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
これは私のインターフェースです:
public interface IClient {
void addClient(ClientBean clt);
}
これは実装です:
public class ClientImpl implements IClient {
private List<ClientBean> ListOfCustomers;
public ClientImpl() {
setListOfCustomers(new ArrayList<ClientBean>());
}
public void addClient(ClientBean clt) {
ListOfCustomers.add(clt);
}
public List<ClientBean> getListOfCustomers() {
return ListOfCustomers;
}
public void setListOfCustomers(List<ClientBean> listOfCustomers) {
ListOfCustomers = listOfCustomers;
}
}
これは私のアスペクトJを作ろうとするクラスです:
@Aspect
public class ClientAspect {
@Pointcut("execution(* *.*(..))")
void anyCallMethod() {}
@Before(value = "anyCallMethod()")
public void befor(JoinPoint joinPoint) {
System.out.println("Before, class: "
+ joinPoint.getSignature().getDeclaringType().getSimpleName()
+ ", method: " + joinPoint.getSignature().getName());
}
@After(value = "anyCallMethod()")
public void after(JoinPoint joinPoint) {
System.out.println("After, class: "
+ joinPoint.getSignature().getDeclaringType().getSimpleName()
+ ", method: " + joinPoint.getSignature().getName());
}
}
テストする man クラスがあり、プロジェクトを実行すると、コンソールに nos ログが表示されます