File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Look up Method Injection in Spring

 
Joe Harry
Ranch Hand
Posts: 10045
3
Eclipse IDE Mac PPC Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Joe Harry
Ranch Hand
Posts: 10045
3
Eclipse IDE Mac PPC Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:

  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic