Win a copy of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques this week in the Server-Side JavaScript and NodeJS forum!
  • 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

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: 17346
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: 17346
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
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic