1

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();
}
M. Deinum
  • 115,695
  • 22
  • 220
  • 224
brendan
  • 384
  • 3
  • 10
  • Please add your code and I will help you more – Panagiotis Bougioukos Mar 15 '21 at 23:51
  • Added code. I also created class with exact same code in the answer I mentioned, https://stackoverflow.com/a/11083493/2980321. Same exception happens – brendan Mar 16 '21 at 00:51
  • @brendan what is the type of your project? is it Spring MVC? Spring Core with some additions? Spring Boot?.. what are your dependencies? as it seems like, you're not having necessary beans to support the web infrastructure. Please include all the necessary information. – Giorgi Tsiklauri Mar 16 '21 at 00:56
  • I will check my Maven dependencies and compare against another project Giorgi. Good idea, thanks – brendan Mar 16 '21 at 01:39

0 Answers0