I have a Spring MVC @Controller
named MyController
. I can inject the Spring Environment
in its constructor:
public MyController(Environment environment) {
…
}
But if I try to inject the same Environment
into a request handler, it fails:
@GetMapping
public String getFoo(Environment environment)
The error message is:
No primary or single unique constructor found for interface org.springframework.core.env.Environment
I note that I can inject the HTTP servlet request in the handler with no problem:
public String getFoo(HttpServletRequest request)
Why can I inject Environment
in the controller constructor, but not in a handler method?
Where in the documentation can I go to get a list of things that can only be injected in one place or the other?