This content has been marked as final.
Show 3 replies
-
1. Re: How to inject based on class name?
jharting Jul 1, 2011 5:22 PM (in response to yangju.richard.yang.pearson.com)You can load the class and then use it for obtaining a CDI Bean from the BeanManager.
-
2. Re: How to inject based on class name?
yangju.richard.yang.pearson.com Jul 1, 2011 6:09 PM (in response to yangju.richard.yang.pearson.com)I thought BeanManager's getBeans() only allows you to look up an already injected Bean. Can it also create one if it does not exist?
If so, could you give me an example? Should I have to take care of the removal of the bean? -
3. Re: How to inject based on class name?
yangju.richard.yang.pearson.com Jul 1, 2011 8:46 PM (in response to yangju.richard.yang.pearson.com)It appears this works:
@Inject @Any Instance<Object> myBeanSource;
Then
Class<?> myClass= Class.forName("MyClassName");
MyType myBean= (MyType) myBeanSource.select(myClass).get();
The myBean is what I need.
I suppose by doing so, there is no need to worry about removing/unregistering the bean created.
Is above a safe way to create a bean?