• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

AOP Not working with Spring 3 MVC application

 
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ??
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Anoop Nair
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Opportunity is missed by most people because it is dressed in overalls and looks like work - Edison. Tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic