In my current project, when this method is called:
public Collection<? extends Object> list_values() throws Exception {
String nome = classe().getSimpleName();
String nome_service = nome+"Service";
String local_service = "com.spring.model."+nome;
Class<?> clazz = Class.forName(local_service.toLowerCase()+"."+nome_service);
Object serv = clazz.newInstance();
Collection<? extends Object> list = (Collection<? extends Object>) serv.getClass().getMethod("lista").invoke(serv);
return list;
}
the application triggers a InvocationTargetException caused by this error:
Caused by: java.lang.NullPointerException
at com.spring.config.generic.service.basicService.lista(basicService.java:51)
where basicService
is the superclass for the class stored in the variable clazz
.
Anyone can tell me what I am doing wrong here? What the right way to make a new instance of this class?
ps.: the line 51 in basicService is placed inside this method:
@Transactional
public List<?> lista() {
return dao.findAll();
}
and the member dao
is defined this way:
@Autowired
protected Dao<E> dao;