GeeCON Prague 2014*
The moose likes Aspect Oriented Programming and the fly likes Logging with Spring AOP for ALL methods Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Frameworks » Aspect Oriented Programming
Bookmark "Logging with Spring AOP for ALL methods" Watch "Logging with Spring AOP for ALL methods" New topic
Author

Logging with Spring AOP for ALL methods

sandeeprajsingh tandon
Ranch Hand

Joined: Mar 06, 2009
Posts: 70
Hi,
i am using spring AOP with Log4j. i have configured log4j.xml and kept it in the classpath. I have an loggingAspect class. the logging method in it works with an around annotation when i give the point cut expression right uptil the method of the service that i want to be invoked for. However, i want an expression such that it works for ALL methods of ALL packages in my application be it of any layer and it may or may not have an interface.

Could someone please provide a expression path that fulfils this?

thanks
sandeepraj
Kathleen Angeles
Ranch Hand

Joined: Aug 06, 2012
Posts: 122

Try this below:



Because there will be some methods not exposed through interfaces, use CGLIB-based proxies.

-k



[SpringSource Certified Spring Professional - Practice Tests]
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

Kathleen Angeles wrote:Try this below:



Because there will be some methods not exposed through interfaces, use CGLIB-based proxies.

-k



[SpringSource Certified Spring Professional - Practice Tests]


I think you have an extraneous "*" in there.

Mark

The only required parts on t apointcut expressions is

Return Type, method, and parenthesis. For the parenthesis of parameters, nothing inside specifically means the method never takes any parameters. Hence your (..) to mean 0 or more parameters.

But returnType and method are the only required parts, and therefore the only two that need "*"

so

"execution(* *(..))" would work.

Personally though I would go a bit more descriptive with

"execution(* *..*.*(..))"

Mark
sandeeprajsingh tandon
Ranch Hand

Joined: Mar 06, 2009
Posts: 70
Mark, what would this as specified by you mean?
"execution(* *..*.*(..))"



Kathleen and mark i would try out both the suggestions tomorrow and give an update.
sandeeprajsingh tandon
Ranch Hand

Joined: Mar 06, 2009
Posts: 70
Thanks to both of you,
I got this working. However i didnt not use ALL STAR approach because it began to log meesages while starting glassfish server.
So i changed it to @Around("execution(* x.y.z..*.*(..))")
so it correctly prints logs for all the pakages that have a similar naming convention i.e. x.y.z.a.SomeClass

Thanks Again.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

sandeeprajsingh tandon wrote:Thanks to both of you,
I got this working. However i didnt not use ALL STAR approach because it began to log meesages while starting glassfish server.
So i changed it to @Around("execution(* x.y.z..*.*(..))")
so it correctly prints logs for all the pakages that have a similar naming convention i.e. x.y.z.a.SomeClass

Thanks Again.


Perfect.

Mark
 
GeeCON Prague 2014
 
subject: Logging with Spring AOP for ALL methods