0
votes

Spring AOP depends on proxy mechanism - J2SE dynamic proxies or using CGLIB(according to the spring documentation). Is it possible to use the AOP mechanism defined by Spring without creating/declaring the beans in the spring application context?

If its not possible with Spring - is AspectJ's Load time Weaving(LTW) or Compile Time Weaving (CTW) would help resolve the issue?

Requirement : Trying to implement logging and transaction management for a old project of mine without declaring the POJO's as spring beans.

2
spring knows only stuff that comes from a bean factory ... - A4L
Yes ApsectJ is the real thing! - A4L
You can use aspectj and weavers with spring's @Configurable. - Sotirios Delimanolis
However logging with a framework like log4j would probably be harder because of the timing on classes being loaded. - Sotirios Delimanolis

2 Answers

2
votes

No, you have to put them under Spring's control. You can't ask Spring to advise beans that it doesn't know about.

No calls to "new"; have to replace those with application context.

1
votes

As stated by @duffymo Spring can only operate on beans declared within its context.

AspectJ, both LTW and CTW, can be used to achieve what you want.

Another tools you might consider is Byteman, which operate at a lower level but has also a lower overhead if performance is an issue for you.