Skip to main content

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

Hi Alex,

Thanks for pointing that out.  I can't believe I missed it.  I had intentionally tried to disable the maven compiler using -Dmaven.main.skip=true, but I must have forgotten to use it for this attempt.

I'm still perturbed as to how to get CDI to inject an AJ aspect though.  I cannot seem to find the magic solution (if one exists) to configure the project such that I can get injections into my Aspect bean.  I'm using LTW and realize that the lifecycle of the aspect is done via AJ and not through CDI.  Nonetheless, in Spring, there is always the SpringBeanAutowiringSupport utility that you can use to wire an existing bean.  Do you know if there is anything equivalent in JEE to accomplish DI in an Aspect?

Thanks,

Eric


On Thu, Jul 12, 2018 at 9:38 PM Alexander Kriegisch <alexander@xxxxxxxxxxxxxx> wrote:
Hi Eric.

The error comes from Maven Compiler, not from AspectJ Maven, i.e. Javac tries to compile something you probably want to be compiled by Ajc. Without seeing your POM I cannot say more, but the configuration with regard to those two plugins is probably the root cause of your problem.

Regards
--
Alexander Kriegisch
https://scrum-master.de


Eric B schrieb am 12.07.2018 23:22:
>
> 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 classUserAccountAspectFactory {
>
>     @Produces
> publicUserAccountStatusAspect
> injectUserAccountStatusAspectDependencies()throwsNoSuchMethodException,
> InvocationTargetException, IllegalAccessException {
> returnUserAccountStatusAspect.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]
>>
>>
>> [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?
>
>
> Thanks,
>
>
> Eric
>
>

_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-users

Back to the top