I created interface:
@RequestMapping("/data")
public interface PersonControllerInterface {
@RequestMapping(value="/person/{id}", method=RequestMethod.GET)
public Person getPersonDetail(@PathVariable final Integer id);
}
and class which implements that interface:
@RestController
public class PersonController implements PersonControllerInterface {
@Override
public Person getPersonDetail(final Integer id) {
final Person p = new Person(id);
return p;
}
}
But after I call GET localhost:8080/data/person/4
. I got:
DEBUG o.s.web.servlet.DispatcherServlet - Could not complete request
java.lang.NullPointerException: null
at com.concretepage.Person.<init>(Person.java:12)
at com.concretepage.PersonController.getPersonDetail(PersonController.java:16)
And the Person
class:
public Person(final Integer id) { this.id = id; }
In jax-rs I can do similar stuff, but in Spring it can't fetch id in path. Are there any solutions on my problem? I really don't want put @PathVariable
annotation in my implementation class.
EDIT: It is not duplicate of fixing NPE. It is a problem with propagating annotations from interface class into implementation.