wood burning stoves 2.0*
The moose likes Spring and the fly likes Look up Method Injection in Spring 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 "Look up Method Injection in Spring" Watch "Look up Method Injection in Spring" New topic
Author

Look up Method Injection in Spring

Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9345
    
    2

Guys,

I'm trying something in the lines of having a Factory class return a Prototype of multiple types.

I have a Factory class as follows:



In the above getXXXPersistence() methods, I would like to have Spring give my objects as I have some injections happening in those implementations. For the very same purpose, I have looked up the Spring docs and came across the look up method injection. But the problem here is that to use the method injection (without having any dependencies on Spring, using the CGLIB proxy), I must declare the above Factory class as abstract as required by the CGLIB proxy. If that be the case, then it violates one principle that I want to maintain which is that the Factory class above will not retain its static methods and the class will not be final. Is there a way to overcome this?

In essence I want Spring to inject a Prototype bean (XXXPersistence) into the Singleton bean (MyXXXFactory). Any suggestions?


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
    
    2

But anyways, I wanted to give it a try. Here is how my first attempt looks like:

My PersistenceFactory:



In my Service layer I let Spring inject my PersistenceFactory as follows:




The error that I face:

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Look up Method Injection in Spring
 
Similar Threads
ClassCast exception in lookup-method injection
Old Issue, but not finding a solution: org.hibernate.LazyInitializationException
Problem in securing the method ( Struts 2 - Spring Security 3.0.3)
Handler Class - Is it correct?
What is the interface?