I am trying to autowire a RequestMappingHandlerMapping
to get a list of all HTTP addresses served as mentioned in this answer and I get the following exception when Tomcat starts.
org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
Why is there no qualifying bean of type RequestMappingHandlerMapping
or how can I make a bean available?
I read this page but I don't think it applies since my project doesn't use Spring Boot. String @EnableWebMvc
isn't in my project also.
Using Spring Framework 4.3.5
@Autowired
private RequestMappingHandlerMapping handlerMapping;
@RequestMapping(value="/endpointdoc", method=RequestMethod.GET)
public void show(Model model) {
model.addAttribute("handlerMethods", this.handlerMapping.getHandlerMethods());
}
@RequestMapping(
method = RequestMethod.POST,
path = "/myHandlerMethods")
@ResponseBody
public String myHandlerMethods() {
log.info("myHandlerMethods");
System.out.println("myHandlerMethods");
return "myHandlerMethods\n" + handlerMapping.getHandlerMethods();
}