permaculture playing cards*
The moose likes Spring and the fly likes AOP Not working with Spring 3 MVC application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "AOP Not working with Spring 3 MVC application " Watch "AOP Not working with Spring 3 MVC application " New topic
Author

AOP Not working with Spring 3 MVC application

Anoop Nair
Ranch Hand

Joined: Oct 29, 2008
Posts: 70
Hi All,

I have a Spring 3.0 MVC application that works fine. I want to introduce AOP in this application. However on doing this I am getting the below exception.



Below is the application code:

Controller


Model interface and implementation:







Can someone please point out what I am doing wrong with this ??
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17258
    
    6

It looks like it is trying to make a Proxy out of a Core Spring MVC object. Why, I am not sure.

But typically in MVC applications, you create two different ApplicationContexts. One for just the web layer components, and one for the middle tier. Your Service and AOP should be in the middle tier. Create a file called applicationContext.xml put it in your WEB-INF directory. Do the component-scan and aop autoproxy in that file. Add in your web.xml the xml for adding the Spring ContextLoaderListener. This will create the middle tier application context.

For your DispatcherServlet, create an xml file called <<<XXX>>>-servlet.xml where the <<<XXX>>> is replaced with the servlet name you give your DispatcherServlet entry in your web.xml. Place this file also in the WEB-INF directory and only include your web layer beans. and <mvc:annotation-driven/>

Also in your middle tier xml you don't need both <context:annotation-config/> and <context:component-scan.../> component-scan includes all the beans you get with annotation-config. So by putting in annotation-config, you are just adding redundancy


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

Joined: Oct 29, 2008
Posts: 70
Thanks Mark.

That works perfectly now.

Although, I still do not understand why it was throwing an exception when the aop config was present in the same file.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17258
    
    6

Anoop Nair wrote:Thanks Mark.

That works perfectly now.

Although, I still do not understand why it was throwing an exception when the aop config was present in the same file.


This just exposed your Web Layer beans to the AOP process and AOP decided it wanted to create a proxy and around a Spring MVC core class.

Mark
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: AOP Not working with Spring 3 MVC application