3

lets say the I have got a bean called with two methods 'foo' and 'goo' and 'goo' is marked with AOP interception call.
is it possible to write any piece of code inside 'foo' in order to invoke 'goo' method not directly but through the proxy wrapper of the bean in order to activate the AOP part of it?

public Class Pojo{ public void foo(){ //what should I write here in order to activate 'goo' in transactional mode?? } @Transactional public void goo(){ } } 

2 Answers 2

5

Yes, but you need to access it through the spring proxy:

public Class Pojo{ @Autowired private Pojo springProxy; public void foo(){ springProxy.goo(); } @Transactional public void goo(){ } } 
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the very quick response. Let me check this and I'll get back to you. I need to check how to use it using invoke() so I'll have a generic solution
This doesn't work in Spring Boot 2.6 anymore (unless you supply spring.main.allow-circular-references=true)
-1

I couldn't use the autowired option. Perhaps it is because I am using reflection to invoke goo() (and any other method as well) from foo().
So eventually what solves my problem was to add in foo() code that will lookup for the Pojo's proxy bean class. and invoke the mothd using Sun invokation on the proxy bean this invoked the AOP call as well.
Couldn't find any better workaround.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.