I'm new to spring and will like move my working code from the controller to the service for best practice, but now I get a:
SEVERE: Servlet.service() for servlet [mvc-dispatcher] in context with path [/xls] threw exception [Request processing failed; nested exception is java.lang.NullPointerException] with root cause java.lang.NullPointerException
MainController.java
public class MainController {
private ListServiceImpl listServiceImpl;
@RequestMapping(value = "/uploadFile", method = RequestMethod.POST)
public ModelAndView upload(@RequestParam("myfile") MultipartFile myFile) throws IOException {
InputStream inputStream = myFile.getInputStream();
ModelAndView model = new ModelAndView("list");
model.addObject("list", listServiceImpl.getList(inputStream) );
return model;
}
ListServiceImpl.java
@Service
public class ListServiceImpl implements ListService {
@Override
public List<UserAndSum> getList(InputStream inputStream) {
List <UserAndSum> list25plus25 = new ArrayList<UserAndSum>();
Workbook workBook = Workbook.getWorkbook(inputStream);
..............
list25plus25 .add(new UserAndSum(previousUser, sum));
return list25plus25;
}
Aucun commentaire:
Enregistrer un commentaire