File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Spring and the fly likes Methods on advice are not being called Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Methods on advice are not being called" Watch "Methods on advice are not being called" New topic
Author

Methods on advice are not being called

rakesh kadulkar
Ranch Hand

Joined: Jul 24, 2008
Posts: 115
Hi

I am new to spring and I am using spring in action 2.0.

I am at chapter 4 trying "creating classic Spring aspects".

I have done everything given in the book but I found that at runtime when I call the perform method it does not first calls the

method on the advice.

I am puting all the code here.



And the rest of the classes are as they are in the book.

i am only keeping the AudienceAdvie class


Please help.

Rakesh Kadulkar
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

1. Try to remove the extra space in the performancePointcut's pattern :


2. What kind of proxy are you using to apply your advices ? I can't see any definition of it.


[My Blog]
All roads lead to JavaRanch
rakesh kadulkar
Ranch Hand

Joined: Jul 24, 2008
Posts: 115
Hi,

I have tried that as well. ".*perform" but still it does not work.

Well the part till where I read in the book there is no description about proxy yet . May be it will come later on.

But I thought it will work as the book was giving different approaches to apply advice to pointcuts.

So may be it will come later on in the chapter but since I stuck up there itself I didnt went further.

As you said is proxy mandatory?



rakesh kadulkar
Ranch Hand

Joined: Jul 24, 2008
Posts: 115
Now as I have read further I found that proxy is required and my example is working fine.

Now I have one doubt that is my AudienceAdvice is implementing ThrowsAdvice interface as well and the apt method.

But from the method which is specified in the pointcut when I thow an exception ( throw new Exception()) the program still ends

calling afterReturning() where as it should call afterThrowing().

I am not getting why this is happening.

rakesh kadulkar
Ranch Hand

Joined: Jul 24, 2008
Posts: 115
This is my modified XML file

Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17259
    
    6

I recommend also reading some more up to date material on Spring, as Spring is on version 3.0 and version 2.5 came out a couple/few years ago. The approach in the book you are reading is the old way of doing things. Today, they are much more simpler, where your Aspect class is now a POJO, not implementing any interfaces, so that you have clean code, and no tight coupling with Spring.

Spring in Action for Spring 3.0 is in the works, but you can sign up for the MEAP program and start learning today.

Good Luck

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
rakesh kadulkar
Ranch Hand

Joined: Jul 24, 2008
Posts: 115
The training company where I work they have started training for spring recently and I am the only person who is upgrading on this technology. The company gives training for spring 2.5 so i have to upgrade myself on spring 2.5.

If I upgrade on it. so later on if I start learing Spring 3.0 I can easily compare between two versions of the spring and I can explain the difference and advantages in best way.

Anyways thaks for the concern.

Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17259
    
    6

rakesh kankavlikar wrote:The training company where I work they have started training for spring recently and I am the only person who is upgrading on this technology. The company gives training for spring 2.5 so i have to upgrade myself on spring 2.5.

If I upgrade on it. so later on if I start learing Spring 3.0 I can easily compare between two versions of the spring and I can explain the difference and advantages in best way.

Anyways thaks for the concern.



Sure, no problem there, but my point is still valid. You should read material that covers 2.5 well and doesn't teach you the old way of doing things.

So in SPring 2.5 they added the aop namespace to make AOP so much easier. They also added Annotations for doing AOP too, if you prefer Annotations over xml.

Using <bean> tags to set up AOP is way too much typing and the old approach.

Mark

rakesh kadulkar
Ranch Hand

Joined: Jul 24, 2008
Posts: 115
Will do that.

Thank you.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Methods on advice are not being called