aspose file tools*
The moose likes Spring and the fly likes Spring AOP with mvc Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Spring AOP with mvc" Watch "Spring AOP with mvc" New topic
Author

Spring AOP with mvc

juniad Ahmed
Greenhorn

Joined: Feb 19, 2011
Posts: 24
Hi,
I have implemented simple Spring AOP example but i have no idea how to implement AOP with MVC, Can any one give me an example of Spring MVC with AOP or link to the site which has this example.

Thanks in advance
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

What do you mean by Spring AOP with MVC?

Spring AOP can advise any Spring Bean. So if you want to advice a class you have as a Spring Bean, you just define your Pointcut expression to match those classes and methods. Then when your ApplicationContext gets created Spring automatically creates Proxies for those classes. There isn't anything special you need to do with Spring MVC to add AOP that you wouldn't do with any Spring application.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
juniad Ahmed
Greenhorn

Joined: Feb 19, 2011
Posts: 24
I applied the advice to the bean but still advice classes doing their job.


program executes successfully and i get the success page. but i dont see the advice classes printing their messages on console
Please help
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

I don't see your PointCut Expression.

What I do see is a format for Spring that is very old, while using the latest Spring jars.

If you are learning Spring, I recommend using the latest versions of Spring and not use any old tutorials or documentation.

Like, i don't implement or extend any Spring class or interface in any of my classes. I keep them 100% POJO. I do like using Annotations, but you don't have to.

For AOP you can use xml to define your pointcut expressions.

Checkout the Spring documentation of Spring AOP. Here is the link for the xml way to do it. I highly recommend doing it this way as it is much simpler.
http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/aop.html#aop-schema

Mark
juniad Ahmed
Greenhorn

Joined: Feb 19, 2011
Posts: 24
Hi Mark,

I tried to implement what you said but was unsuccessful. mark it will be really nice for me or any new Spring programmer if you can give a sample program with comments.

Thanks
juniad Ahmed
Greenhorn

Joined: Feb 19, 2011
Posts: 24
Hi Mark,
I got the example working.
Here is the code which is working fine. If you feel some think can be improved please comment.

Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

Yeah, that looks nice. You are now using the Annotations and now your classes are truly pojos. Which means you can write simple unit tests for all the classes including the Aspect class. But you will have to stub/mock out a JoinPoint object. There is a way to have Spring go into the JoinPoint directly for you. Examples of that are in the Spring Documentation under the AOP section.

Good Luck

Mark
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Spring AOP with mvc
 
Similar Threads
Seam AOP
AOP
Spring AOP + OSGI
AOP
uses of aop in spring