aspose file tools*
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
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:-)
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: how to set a bean property of type java.lang.Class using Spring DI?