This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Spring and the fly likes Spring error when injecting beans Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Spring error when injecting beans" Watch "Spring error when injecting beans" New topic

Spring error when injecting beans

Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9345


I have a Spring web application in which I inject some beans on my action class. When I run my app in Tomcat, I get the following exception:

From where did the $Proxy20 come from?

SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9345

Allright! Got rid of this one as well. I was not implementing an interface in one of my bean that I was injecting in my facade layer.
Mark Spritzler

Joined: Feb 05, 2001
Posts: 17249

Yep Spring creates DynamicProxy objects when it needs to add functionality to your code, and to create a DynamicProxy, you class has to implement an interface because you pass the interface class to the constructor of a DynamicProxy. This way from the client calling code perspective, it has a class that implements your interface.

There is another work around, but always create interfaces anyway, it is great Java coding best practice.

But if you include CGLib's jar file in your class path then Spring will be able to create Proxy objects in which the Proxy extends your class.


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

Joined: Sep 26, 2006
Posts: 9345

we just did implement a dynamic dispatching proxy for one of our business requirements and together with this exception, things became much more clearer to me.
wood burning stoves
subject: Spring error when injecting beans
Similar Threads
HibernateDaoSupport not compatible with JSON
No Dialect mapping for JDBC type: -1
java.lang.NoClassDefFoundError for interface of included project
Struts2 session bean and Container.setScopeStrategy exception
Spring Aspects not working in Struts 2