NFE
NFE

Reputation: 1187

Aspect will not execute if it is in different module in Spring Boot

I have multiple modules like Module A, Module B and Common Module. I have added aspect into common module. As per expression when any method contain specific annotation, it will call aspect before. But it didn't work. If I copy same aspect class and add into module (Module A) itself, it works for that module (Module A) only. Why is it not working for common module? Do we have to do anything special to share in-between modules?

I use similar annotation which mentioned in previous question: Multiple Audit table by using AOP and Spring boot

    @Aspect
    @Component
    public class AuditAspect {

        @AfterReturning(value = "@annotation(auditable)")
        public void save(Auditing audit) {
        }
    }

Upvotes: 2

Views: 1625

Answers (3)

Rujal Shrestha
Rujal Shrestha

Reputation: 362

I followed this link and finally it worked for me.

What I did is made some changes inside build tag in pom.xml for both aspect module and application module.

TestProject source code can be found here

Upvotes: 1

Krishna Gond
Krishna Gond

Reputation: 143

Try to provide full path of "Auditing" in advice as below -

 @AfterReturning(value = "@annotation(FULL_PATH.Auditing)")
        public void save(Auditing audit) {
 }

Upvotes: 0

Adrian
Adrian

Reputation: 3134

In module A you should specify beans from common module, smth like

<context:component-scan base-package="org.common" />

Upvotes: 0

Related Questions