I am trying to validate the values returned by a list of methods using java reflection and @PostConstruct
spring annotation as it is depicted in the following code snippet :
@Serivce("appConfigService")
public class AppConfigServiceImpl implements AppConfigService{
//rest of source code including constructor and other methods is omitted
@Override
public String getServerURL(){//example of a method I am invoking in the postConstruct phase
//method body omitted
}
@PostConstruct
public void postConstruct() {
try {
Class<AppConfigServiceImpl> classObject = AppConfigServiceImpl.class;
AppConfigServiceImpl appConfigServiceImpl = classObject.newInstance();
Method[] methods = classObject.getMethods();
for(Method method: methods)
method.invoke(appConfigServiceImpl);
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | InstantiationException e) {
e.printStackTrace();
}
}
}
However when spring executes the postConstruct()
method a java.lang.reflect.InvocationTargetException
is thrown. I could not figure out the source of the exception. Any help will be more than welcome.
Aucun commentaire:
Enregistrer un commentaire