The essence of the question: I have

@RestController @RequestMapping(value = "/features/{uin}", method = RequestMethod.GET) public class RestController { private Modul modul; @Resource(name = "modulService") private ModuleDAO modulService; ... } 

The {uin} parameter will be used in all methods to search for the entity. Is it possible to find this entity directly when creating a bean, for further use in the methods. For example, like this:

  @RestController @RequestMapping(value = "/features/{uin}", method = RequestMethod.GET) public class RestController { private Modul modul; @Resource(name = "modulService") private ModuleDAO modulService; ... public RestController(@PathVariable("uin") String uin){ this.modul = modulService.findByUin(uin); ... } ... } 

But I don’t seem to be able to do this in the class constructor, they say that it’s impossible to inject a parameter.

    1 answer 1

    I do not think that this is possible. The constructor of the controller is called once - at the start of the application, and not with each request, so it is not possible to thus bind the variable from the request.