@Controller
public class TestController {
private TestService testService;
@Autowired
public TestController(TestService testService) {
this.testService= testService;
}
@GetMapping
@ResponseBody
private void controlTarget() {
testService.test();
}
上面代码会报空指针异常。
解决办法:把private void controlTarget() 方法的修饰符private修改为public。
原因不是很清楚:有空研究一下@Controller的原理
ps:浪费我1小时。