You can load the class and then use it for obtaining a CDI Bean from the BeanManager.
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?
It appears this works:
@Inject @Any Instance<Object> myBeanSource;
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?