[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-users] Using AspectJ Aspect with CDI and dependency injection

I'm trying to figure out a way to inject dependencies into an Aspect that is running under Wildfly 10 with CDI.

From what I can tell, by definition, I need to have a no-argument constructor in the Aspect, which already implies AJ cannot support the constructor injection pattern. Please correct me if I am mistaken.

Secondly, once I have fields annotated withÂ@Inject, I'm not sure how to tell CDI to inject beans into my aspect. If I remember correctly, in Spring, I can use the .aspectOf() as a factory-method to declare the bean to Spring. This was accomplished using XML definitions.

However, when I try to do something similar in CDI, usingÂ@Produces, it does not seem to be work; the compiler throws errors that the .aspectOf() method in my aspect does not exist.

public class UserAccountAspectFactory {

public UserAccountStatusAspect injectUserAccountStatusAspectDependencies() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
return UserAccountStatusAspect.aspectOf();

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project adams-aspects: Compilation failure
[ERROR] /C:/dev/Projects/develop/aspects/src/main/java/model/interceptor/UserAccountAspectFactory.java:[11,39] cannot find symbol
[ERROR]Â Âsymbol:Â Âmethod aspectOf()
[ERROR]Â Âlocation: class model.interceptor.UserAccountStatusAspect
[ERROR] -> [Help 1]

Which surprises me b/c when I look at the UserAccountStatusAspect.class file, I see that ajc has added the .aspectOf() method to the compiled class.

I'm obviously doing something wrong, but not quite sure what.

Can anyone point me in the right direction please?