This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell 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


JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Spring error when injecting beans" Watch "Spring error when injecting beans" New topic
Author

Spring error when injecting beans

Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9398
    
    2

Guys,

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: 9398
    
    2

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
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

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.

Mark


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: 9398
    
    2

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.
 
GeeCON Prague 2014
 
subject: Spring error when injecting beans