Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

AOP Not working with Spring 3 MVC application

 
Anoop Nair
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 ??
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac 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
Sheriff
Posts: 17278
6
IntelliJ IDE Mac 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic