Many thanks for the response .. Andy. I used perthis aspect association in perclause attribute of concrete aspect definition and worked fine in the sample application.
Please find below the definition of concrete aspect.with
perthis aspect association.
<concrete-aspect name="aop.field2.MyField2Aspect"
extends="aop.field2.Field2Aspect" perclause="perthis(getField2() || setField2())">
<pointcut name="getField2" _expression_="get(@aop.field2.Field2 * *)" />
<pointcut name="setField2" _expression_="set(@aop.field2.Field2 * *)" />
</concrete-aspect>
JFYI that load time weaving is employed and the version of aspectJ used is 1.8.5 and the version of java is 1.7 in testing with sample application.
Please consider the below aspect. In this aspect, a string variable name is annotated with @Field. As per aspect defined for the annotation @Field, it should return the value "Andy" but it is null. When I created a helper object of FieldHelper.java, I can see the value "Andy".
Field2Aspect.java
package aop.field2;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import aop.field.Field;
import aop.helper.FieldHelper;
@Aspect
public abstract class Field2Aspect {
private FieldHelper fieldHelper = new FieldHelper();
@Field
public String name;
@Pointcut
public abstract void getField2();
@Pointcut
public abstract void setField2();
@Around("getField2()")
public String getFieldValue() {
String output = null;
if (name != null) {
output = name + "Clement";
} else {
output = "Clement";
}
System.out.println("fieldHelper name --> " + fieldHelper.getName());
System.out.println("In getFieldValue() of Field2Aspect - name : "
+ name);
System.out
.println("In getFieldValue() of Field2Aspect - getting field value : "
+ output);
System.out.println("fieldHelper object --> " + fieldHelper.hashCode());
System.out.println("fieldHelper object --> " + fieldHelper.toString());
return output;
}
@Around("setField2()")
public void setFieldValue(final ProceedingJoinPoint invocation) {
System.out.println("In setFieldValue() of Field2Aspect");
throw new RuntimeException();
}
}
FieldHelper .java
package aop.helper;
import aop.field.Field;
public class FieldHelper {
@Field
private String name;
public String getName() {
System.out.println("In getName() of FieldHelper : " + name);
return name;
}
}
My first question is that will a annotated variable within an aspect that requires another aspect to load its value not work ? Should this scenario be done using only helper or holder classes ?
When I employed the solution arrived using the sample application in my real application, deployment gets failed with the below error when perclause="perthis(pointcut)" attribute is used in aop.xml for concrete aspect definitions. My real application uses MBeans and this error comes for all MBeans and am running on Wildfly 8.2.0 application server. When I remove this attribute, deployment happens fine.
Caused by: java.lang.ClassFormatError: Duplicate method name&signature in class file
JFYI that When I looked into the link
https://bugs.eclipse.org/bugs/show_bug.cgi?id=223226, I saw the same error and this was resolved in the version 1.6.1. Also, load time weaving is employed and the version of aspectJ used
is 1.8.5 and the version of java is 1.7 in testing with real application.
As the default aspect association is SINGLETON, could you please help me about how to resolve this error as I need to use perclause="perthis(pointcut)" and the aspectJ version employed is 1.8.5. Should I need to go for any other aspectJ version to resolve this error. Please guide me.
Many thanks for the help.
Sridhar Thiyagarajan