mapped to org.springframework.boot.autoconfigure.web.servlet.error.basicerrorcontroller#error(httpservletrequest)
时间: 2023-05-03 16:01:11 浏览: 420
这是一个 Spring Boot 自动配置的问题,意思是将错误映射到 org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController#error 方法,该方法需要一个 HttpServletRequest 参数。
相关问题
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]: Ambiguous mapping. Cannot map 'sendEmail' method com.example.spring.controller.Others.SendEmail#sendEmail(SendEmailFilter) to { [/send]}: There is already 'rabbitMqController' bean method com.example.spring.controller.Others.RabbitMqController#send() mapped. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1751) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:599) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:521) at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:326) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:324) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:961) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:915) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:584) at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:146) at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:730) at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:432) at org.springframework.boot.SpringApplication.run(SpringApplication.java:308) at org.springframework.boot.SpringApplication.run(SpringApplication.java:1302) at org.springframework.boot.SpringApplication.run(SpringApplication.java:1291) at com.example.spring.Application.main(Application.java:11) Caused by: java.lang.IllegalStateException: Ambiguous mapping. Cannot map 'sendEmail' method
这个错误是因为在Spring的Web MVC配置中,有一个方法(com.example.spring.controller.Others.SendEmail)被映射到了多个URL上,导致无法确定应该映射到哪个URL。这种情况被称为“模糊映射(Ambiguous mapping)”。需要修改映射关系,确保每个方法只被映射到单一的URL上。
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'handlerExceptionResolver' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.web.servlet.HandlerExceptionResolver]: Factory method 'handlerExceptionResolver' threw exception; nested exception is java.lang.IllegalStateException: Ambiguous @ExceptionHandler method mapped for [class org.springframework.web.bind.MethodArgumentNotValidException]: {protected org.springframework.http.ResponseEntity com.example.mybatisplusspringboot.exception.RestExceptionHandler.handleMethodArgumentNotValid(org.springframework.web.bind.MethodArgumentNotValidException,org.springframework.http.HttpHeaders,org.springframework.http.HttpStatus,org.springframework.web.context.request.WebRequest), public final org.springframework.http.ResponseEntity org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler.handleException(java.lang.Exception,org.springframework.web.context.request.WebRequest) throws java.lang.Exception}
这个异常通常是由于 Spring MVC 中存在多个异常处理方法处理同一种异常类型,从而导致无法确定使用哪个方法来处理该异常。在这种情况下,Spring 将抛出上述异常。
具体来说,这个异常是由于在创建 `HandlerExceptionResolver` 时出现了问题。`HandlerExceptionResolver` 是 Spring MVC 用于处理异常的接口,用于将异常映射到特定的视图或响应中。
要解决这个问题,您可以采取以下措施之一:
1. 删除其中一个异常处理方法,以确保只有一个方法处理该异常类型。
2. 在其中一个异常处理方法上添加更具体的异常类型,以确保每个异常处理方法处理不同的异常类型。
3. 通过指定 `@Order` 或实现 `Ordered` 接口来明确指定处理器的执行顺序,以确保使用正确的异常处理方法来处理该异常类型。
您还可以查看异常堆栈跟踪,以获取更多有关此问题的信息。
阅读全文