Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No qualifying bean of type [org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping] #2237

Closed
ptahchiev opened this issue Dec 26, 2014 · 8 comments
Assignees
Labels
type: bug A general bug
Milestone

Comments

@ptahchiev
Copy link
Contributor

Following this question here:

http://stackoverflow.com/questions/26890727/spring-boot-issue-while-using-smvcurl-tag

I get the same error:

2014-12-26 12:27:22,489 [http-nio-8112-exec-5] ERROR: Servlet.service() for servlet jsp threw exception
org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping] is defined: expected single matching bean but found 4: fallbackMapping,endpointHandlerMapping,repositoryExporterHandlerMapping,requestMappingHandlerMapping
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:365)
@philwebb philwebb added this to the 1.2.1 milestone Dec 26, 2014
@philwebb philwebb added the type: bug A general bug label Dec 26, 2014
@philwebb philwebb modified the milestones: 1.1.11, 1.2.1 Dec 26, 2014
@philwebb
Copy link
Member

What version of Spring Boot are you using?

@ptahchiev
Copy link
Contributor Author

spring-boot-1.2.0.RELEASE

@philwebb
Copy link
Member

org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping] is defined: expected single matching bean but found 2: endpointHandlerMapping,requestMappingHandlerMapping
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:332)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:298)
    at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:968)
    at org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder.getRequestMappingInfoHandlerMapping(MvcUriComponentsBuilder.java:340)
    at org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder.fromMappingName(MvcUriComponentsBuilder.java:242)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)`

@ptahchiev
Copy link
Contributor Author

I got the 1.2.1 release, and I can see the @Primary annotation but I still get this exception:

    Stacktrace:] with root cause
org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping] is defined: expected single matching bean but found 4: fallbackMapping,endpointHandlerMapping,repositoryExporterHandlerMapping,requestMappingHandlerMapping
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:365)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:331)
    at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:968)
    at org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder.getRequestMappingInfoHandlerMapping(MvcUriComponentsBuilder.java:360)
    at org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder.fromMappingName(MvcUriComponentsBuilder.java:262)

@philwebb philwebb reopened this Jan 13, 2015
@wilkinsona wilkinsona modified the milestones: 1.2.2, 1.1.11 Jan 14, 2015
@wilkinsona wilkinsona self-assigned this Jan 15, 2015
@wilkinsona
Copy link
Member

@paranoiabla I can't reproduce the failure with 1.2.1.RELEASE. I have a controller:

@RestController
@RequestMapping("/")
public class MyController {

    @RequestMapping("mapping")
    public String mapping() {
        return MvcUriComponentsBuilder.fromMappingName("MC#mapping").build();
    }

}

And this test that passes with 1.2.1.RELEASE:

@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = Gh2237Application.class)
@IntegrationTest("server.port=0")
@WebAppConfiguration
public class Gh2237ApplicationTests {

    @Autowired
    private ApplicationContext context;

    @Value("${local.server.port}")
    private int port;

    private RestTemplate restTemplate = new TestRestTemplate();

    @Test
    public void primaryRequestMappingHandlerMapping() {
        assertEquals(4, this.context.getBeansOfType(RequestMappingHandlerMapping.class).size());

        ResponseEntity<String> entity = this.restTemplate.getForEntity(
                "http://localhost:" + this.port + "/mapping", String.class);
        assertEquals(HttpStatus.OK, entity.getStatusCode());
        assertEquals("http://localhost:" + this.port + "/mapping", entity.getBody());
    }
}

It fails if I drop back to 1.2.0.RELEASE with the same four beans your app has:

org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping] is defined: expected single matching bean but found 4: fallbackMapping,endpointHandlerMapping,repositoryExporterHandlerMapping,requestMappingHandlerMapping

If you'd like us to investigate further please provide us with a small sample that reproduces the problem on 1.2.1.RELEASE.

@wilkinsona wilkinsona added the status: waiting-for-feedback We need additional information before we can continue label Jan 15, 2015
@ptahchiev
Copy link
Contributor Author

Hi @philwebb It works now. Turns out I had forgotten the @EnableWebMVC annotation so spring-boot was not kicking it. After removing the @EnableWebMVC it works now. Thanks to @olivergierke for the tip :)

@wilkinsona wilkinsona modified the milestones: 1.2.1, 1.2.2 Jan 15, 2015
@wilkinsona wilkinsona removed the status: waiting-for-feedback We need additional information before we can continue label Jan 15, 2015
@fawzyj
Copy link

fawzyj commented Jul 29, 2015

Why adding @EnableWebMVC cause this problem?
I need to customize my mvc configuration, so i add @EnableWebMVC on my configuration class, it cause the problem outlined here...
so how to keep @EnableWebMVC and prevent this problem?
Thanks

@wilkinsona
Copy link
Member

This is covered in the reference documentation:

If you want to take complete control of Spring MVC, you can add your own @Configuration annotated with @EnableWebMvc. If you want to keep Spring Boot MVC features, and you just want to add additional MVC configuration (interceptors, formatters, view controllers etc.) you can add your own @Bean of type WebMvcConfigurerAdapter, but without @EnableWebMvc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

4 participants