I have a class that needs to be initialized dynamically like this:
void doSth(classsuffix) throws Exception {
String classname =
"org.test.classname"+classsuffix; //classsuffix is dynamic
Class<?> clazz;
clazz = Class.forName(classname);
TestInterface test = (TestInterface) clazz.newInstance();
}
Paired with a example class
public class classnameOne implements TestInterface{
@Inject
private Logger log;
// Some more functions and stuff
}
The problem is that log
in the classnameOne
class will be null
when initialized. I need that logger to be there tho, so is there any possibility to initialize injected properties when creating the class with newInstance()
?
Aucun commentaire:
Enregistrer un commentaire