This week's book giveaway is in the Design forum.
We're giving away four copies of Building Microservices and have Sam Newman on-line!
See this thread for details.
The moose likes Spring and the fly likes how to set a bean property of type java.lang.Class using Spring DI? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Building Microservices this week in the Design forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "how to set a bean property of type java.lang.Class using Spring DI?" Watch "how to set a bean property of type java.lang.Class using Spring DI?" New topic
Author

how to set a bean property of type java.lang.Class using Spring DI?

Philippe Desrosiers
Ranch Hand

Joined: Mar 29, 2006
Posts: 138
I guess the title says it all, but: I have a bean with a property of type java.lang.Class. How can I populate this property using a Spring Context.xml? Is there some sort of Spring ClassFactoryBean I can use?

So, something like this:


Only problem is, there's no such thing as org.springframework.beas.factory.config.ClassFactoryBean.

Has anyone done this before?

On a related note, is there some way to specify the run-time type, for classes that use Generics?
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

It should work with -



As for the second part - that won't work due to Type Erasure.


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Philippe Desrosiers
Ranch Hand

Joined: Mar 29, 2006
Posts: 138
Hah! Sweet! Thanks Nathan:-)
 
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: how to set a bean property of type java.lang.Class using Spring DI?
 
It's not a secret anymore!