This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
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

JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Look up Method Injection in Spring" Watch "Look up Method Injection in Spring" New topic

Look up Method Injection in Spring

Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9952


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: 9952

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:
subject: Look up Method Injection in Spring
It's not a secret anymore!