Error creating bean with name requestMappingHandlerMapping defined in class path resou

Error creating bean with name requestMappingHandlerMapping defined in class path resou

  • 问题描述
  • 问题分析
  • 问题解决

问题描述

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'requestMappingHandlerMapping' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: Invalid mapping on handler class [com.cloud.controller.PaymentController]: public com.cloud.entities.CommonResult com.cloud.controller.PaymentController.getPaymentById(java.lang.Long)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1796) ~[spring-beans-5.2.2.RELEASE.jar:5.2.2.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:595) ~[spring-beans-5.2.2.RELEASE.jar:5.2.2.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517) ~[spring-beans-5.2.2.RELEASE.jar:5.2.2.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323) ~[spring-beans-5.2.2.RELEASE.jar:5.2.2.RELEASE]
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.2.2.RELEASE.jar:5.2.2.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321) ~[spring-beans-5.2.2.RELEASE.jar:5.2.2.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-5.2.2.RELEASE.jar:5.2.2.RELEASE]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:879) ~[spring-beans-5.2.2.RELEASE.jar:5.2.2.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:878) ~[spring-context-5.2.2.RELEASE.jar:5.2.2.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550) ~[spring-context-5.2.2.RELEASE.jar:5.2.2.RELEASE]
	..........

问题分析

springboot启动的时候失败,Error creating bean with name ‘requestMappingHandlerMapping’ defined in class path resource主要有以下几种可能:
1.Controller的方法名重复
也就是同一个Controller下面的方法名是不能重复的,因为这个就会有bean的冲突
2.@RequestMapping()中的参数存在非法字符或者写法不正确

@RequestMapping("/get/{id}")  //注意RESTful的正确格式
    public CommonResult getPaymentById(@PathVariable("id")Long id){
        Payment payment =paymentService.getPaymentById(id);

        if(payment != null){
            return  new CommonResult(200,"查询成功",payment);
        }else{
            return  new CommonResult(444,"没有对应记录,查询ID:" +id);
        }
    }

问题解决

同一个类下面的Controller检查一下,看看内部是否存在方法名冲突
,还有就是检查一下@RequestMapping()中的参数存在非法字符或者写法不正确

你可能感兴趣的:(java)