in Education by
I am new to Spring AOP. Using annotation based Spring configuration: @Configuration @EnableAspectJAutoProxy(proxyTargetClass=true) @ComponentScan({"sk.lkrnac"}) Aspect: @Aspect @Component public class TestAspect { @Before("execution(* *(..))") public void logJoinPoint(JoinPoint joinPoint){ .... } } Spring compoment: package sk.lkrnac.testaop; @Component public class TestComponent{ @PostConstruct public void init(){ testMethod(); } public void testMethod() { return; } } How can I intercept all public methods that are called by Spring framework itself? (e.g. TestComponent.init() during creation of the TestComponent instance by Spring) Currently I am able to intercept only TestComponent.testMethod() by invoking: TestComponent testComponent = springContext.getBean(TestComponent.class); testComponent.testMethod(); JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
This is a common issue you run into with Spring AOP. Spring accomplishes AOP by proxying advised classes. In your case, your TestComponent instances will be wrapped in a run-time proxy class that provides the "hooks" for any aspect advice to be applied. This works very well when methods are called from outside the class, but as you have discovered it doesn't work on internal calls. The reason is that internal calls will not pass the proxy barrier, thus will not trigger the aspect. There are primarily two ways around this. One is to fetch an instance of the (proxied) bean from the context. This is what you have already tried with success. The other way is to use something called load-time weaving. When using this, AOP advices are added to a class ("weaved" into it) by a custom class-loader by injecting byte-code into the class definition. The Spring documentation has more on this. There is a third way, which is called "compile time weaving". In this scenario, your AOP advices are statically weaved into each advised class when you compile it.

Related questions

0 votes
    Facing issue in session with the upgrade of my application to Spring 4.1.9 and Hibernate 4.3.11.. ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 14, 2022 in Education by JackTerrance
0 votes
    I have quite a large code base using a variety of different ADO technologies (i.e. some EF and in ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 26, 2022 in Education by JackTerrance
0 votes
    I have an aspect advice like following @AfterReturning("execution(* de.ojk.platform.servicelayer.session. ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 13, 2022 in Education by JackTerrance
0 votes
    I have been able to define multiple aspects (one is @Before and another is @Around) using Spring AOP ( ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 18, 2022 in Education by JackTerrance
+1 vote
    What AOP stands for in Spring? A - Aspect Oriented Programming B - Any Object Programming C - Asset Oriented Programming D - Asset Oriented Protocol...
asked Oct 14, 2020 in Technology by JackTerrance
0 votes
    I wanted to try the Spring 3.1 Cache Abstraction, annotating some methods with @Cachable. This is working ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 7, 2022 in Education by JackTerrance
0 votes
    I wanted to try the Spring 3.1 Cache Abstraction, annotating some methods with @Cachable. This is working ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 5, 2022 in Education by JackTerrance
0 votes
    What is an IOC container in Spring boot?...
asked Jul 8, 2021 by JackTerrance
+1 vote
    Which are the modules of core container in Spring? A - Beans, Core, Context, SpEL B - Core, Context, ORM, Web C - Core, Context, Aspects, Test D - Bean, Core, Context, Test...
asked Oct 14, 2020 in Technology by JackTerrance
0 votes
    I have the below query to fetch specific columns of a entity/table from database @Query("SELECT u.email, ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 21, 2022 in Education by JackTerrance
0 votes
    What is the process of defining two or more methods within same class that have same name but different ... questions and answers pdf, java interview questions for beginners...
asked Oct 26, 2021 in Education by JackTerrance
0 votes
    Which of these methods can be used to obtain the reference to the container that generated a ContainerEvent? (a) ... Handling of Java Select the correct answer from above options...
asked Feb 24, 2022 in Education by JackTerrance
0 votes
    Which of these methods can be used to get reference to a component that was removed from a container? (a) ... Event Handling of Java Select the correct answer from above options...
asked Feb 24, 2022 in Education by JackTerrance
0 votes
    Which of these methods can be used to obtain the reference to the container that generated a ContainerEvent? ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Oct 24, 2021 in Education by JackTerrance
...