• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

AOP Not working with Spring 3 MVC application

 
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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
reply
    Bookmark Topic Watch Topic
  • New Topic