-1

For e.g. when I try to invoke the following method which is part of PersonController

@RequestMapping("/selectnamelbyid")     
public Template selectNamesbyID(@RequestParam(value = "id") String id) {...

using the code below

PersonController personController = new PersonController();
personController.selectNamesbyID(id);

it throws a nullpointer. I am trying to centralize the data fetching logic to the controller class by doing this. Can someone tell what am I doing wrong?

sarego
  • 2,907
  • 6
  • 27
  • 38

1 Answers1

1

I believe PersonController should be initialized by spring container. It can be injected into your code somewhere but it will not work if you new this instance manually.

Joey Yi Zhao
  • 30,508
  • 51
  • 183
  • 377