错误

运行报错:
错误原因:两个Controller映射同一个一个名字
解决方法:将@RequestMapping(“api/list”),括号里改一个名称

org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘requestMappingHandlerMapping’ defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration E n a b l e W e b M v c C o n f i g u r a t i o n . c l a s s ] : I n v o c a t i o n o f i n i t m e t h o d f a i l e d ; n e s t e d e x c e p t i o n i s j a v a . l a n g . I l l e g a l S t a t e E x c e p t i o n : A m b i g u o u s m a p p i n g . C a n n o t m a p ′ w h i t e L i s t C o n t r o l l e r ′ m e t h o d p u b l i c c o m . t r i t o n s f s . c o r e . b e a n . R e s p o n s e B e a n c o m . t r i t o n s f s . c o n t r o l l e r . W h i t e L i s t C o n t r o l l e r . i n s e r t ( j a v a x . s e r v l e t . h t t p . H t t p S e r v l e t R e q u e s t ) t o [ / a p i / l i s t / i n s e r t ] , m e t h o d s = [ P O S T ] : T h e r e i s a l r e a d y ′ b l a c k L i s t C o n t r o l l e r ′ b e a n m e t h o d p u b l i c c o m . t r i t o n s f s . c o r e . b e a n . R e s p o n s e B e a n c o m . t r i t o n s f s . c o n t r o l l e r . B l a c k L i s t C o n t r o l l e r . i n s e r t ( j a v a x . s e r v l e t . h t t p . H t t p S e r v l e t R e q u e s t ) m a p p e d . a t o r g . s p r i n g f r a m e w o r k . b e a n s . f a c t o r y . s u p p o r t . A b s t r a c t A u t o w i r e C a p a b l e B e a n F a c t o r y . i n i t i a l i z e B e a n ( A b s t r a c t A u t o w i r e C a p a b l e B e a n F a c t o r y . j a v a : 1706 ) a t o r g . s p r i n g f r a m e w o r k . b e a n s . f a c t o r y . s u p p o r t . A b s t r a c t A u t o w i r e C a p a b l e B e a n F a c t o r y . d o C r e a t e B e a n ( A b s t r a c t A u t o w i r e C a p a b l e B e a n F a c t o r y . j a v a : 579 ) a t o r g . s p r i n g f r a m e w o r k . b e a n s . f a c t o r y . s u p p o r t . A b s t r a c t A u t o w i r e C a p a b l e B e a n F a c t o r y . c r e a t e B e a n ( A b s t r a c t A u t o w i r e C a p a b l e B e a n F a c t o r y . j a v a : 501 ) a t o r g . s p r i n g f r a m e w o r k . b e a n s . f a c t o r y . s u p p o r t . A b s t r a c t B e a n F a c t o r y . l a m b d a EnableWebMvcConfiguration.class]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: Ambiguous mapping. Cannot map 'whiteListController' method public com.tritonsfs.core.bean.ResponseBean com.tritonsfs.controller.WhiteListController.insert(javax.servlet.http.HttpServletRequest) to {[/api/list/insert],methods=[POST]}: There is already 'blackListController' bean method public com.tritonsfs.core.bean.ResponseBean com.tritonsfs.controller.BlackListController.insert(javax.servlet.http.HttpServletRequest) mapped. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1706) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:579) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:501) at org.springframework.beans.factory.support.AbstractBeanFactory.lambda EnableWebMvcConfiguration.class]:Invocationofinitmethodfailed;nestedexceptionisjava.lang.IllegalStateException:Ambiguousmapping.CannotmapwhiteListControllermethodpubliccom.tritonsfs.core.bean.ResponseBeancom.tritonsfs.controller.WhiteListController.insert(javax.servlet.http.HttpServletRequest)to[/api/list/insert],methods=[POST]:ThereisalreadyblackListControllerbeanmethodpubliccom.tritonsfs.core.bean.ResponseBeancom.tritonsfs.controller.BlackListController.insert(javax.servlet.http.HttpServletRequest)mapped.atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1706)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:579)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:501)atorg.springframework.beans.factory.support.AbstractBeanFactory.lambdadoGetBean 0 ( A b s t r a c t B e a n F a c t o r y . j a v a : 317 ) a t o r g . s p r i n g f r a m e w o r k . b e a n s . f a c t o r y . s u p p o r t . D e f a u l t S i n g l e t o n B e a n R e g i s t r y . g e t S i n g l e t o n ( D e f a u l t S i n g l e t o n B e a n R e g i s t r y . j a v a : 228 ) a t o r g . s p r i n g f r a m e w o r k . b e a n s . f a c t o r y . s u p p o r t . A b s t r a c t B e a n F a c t o r y . d o G e t B e a n ( A b s t r a c t B e a n F a c t o r y . j a v a : 315 ) a t o r g . s p r i n g f r a m e w o r k . b e a n s . f a c t o r y . s u p p o r t . A b s t r a c t B e a n F a c t o r y . g e t B e a n ( A b s t r a c t B e a n F a c t o r y . j a v a : 199 ) a t o r g . s p r i n g f r a m e w o r k . b e a n s . f a c t o r y . s u p p o r t . D e f a u l t L i s t a b l e B e a n F a c t o r y . p r e I n s t a n t i a t e S i n g l e t o n s ( D e f a u l t L i s t a b l e B e a n F a c t o r y . j a v a : 760 ) a t o r g . s p r i n g f r a m e w o r k . c o n t e x t . s u p p o r t . A b s t r a c t A p p l i c a t i o n C o n t e x t . f i n i s h B e a n F a c t o r y I n i t i a l i z a t i o n ( A b s t r a c t A p p l i c a t i o n C o n t e x t . j a v a : 869 ) a t o r g . s p r i n g f r a m e w o r k . c o n t e x t . s u p p o r t . A b s t r a c t A p p l i c a t i o n C o n t e x t . r e f r e s h ( A b s t r a c t A p p l i c a t i o n C o n t e x t . j a v a : 550 ) a t o r g . s p r i n g f r a m e w o r k . b o o t . w e b . s e r v l e t . c o n t e x t . S e r v l e t W e b S e r v e r A p p l i c a t i o n C o n t e x t . r e f r e s h ( S e r v l e t W e b S e r v e r A p p l i c a t i o n C o n t e x t . j a v a : 140 ) a t o r g . s p r i n g f r a m e w o r k . b o o t . S p r i n g A p p l i c a t i o n . r e f r e s h ( S p r i n g A p p l i c a t i o n . j a v a : 759 ) a t o r g . s p r i n g f r a m e w o r k . b o o t . S p r i n g A p p l i c a t i o n . r e f r e s h C o n t e x t ( S p r i n g A p p l i c a t i o n . j a v a : 395 ) a t o r g . s p r i n g f r a m e w o r k . b o o t . S p r i n g A p p l i c a t i o n . r u n ( S p r i n g A p p l i c a t i o n . j a v a : 327 ) a t c o m . t r i t o n s f s . P a y W e b A p p l i c a t i o n . m a i n ( P a y W e b A p p l i c a t i o n . j a v a : 28 ) a t s u n . r e f l e c t . N a t i v e M e t h o d A c c e s s o r I m p l . i n v o k e 0 ( N a t i v e M e t h o d ) a t s u n . r e f l e c t . N a t i v e M e t h o d A c c e s s o r I m p l . i n v o k e ( U n k n o w n S o u r c e ) a t s u n . r e f l e c t . D e l e g a t i n g M e t h o d A c c e s s o r I m p l . i n v o k e ( U n k n o w n S o u r c e ) a t j a v a . l a n g . r e f l e c t . M e t h o d . i n v o k e ( U n k n o w n S o u r c e ) a t o r g . s p r i n g f r a m e w o r k . b o o t . d e v t o o l s . r e s t a r t . R e s t a r t L a u n c h e r . r u n ( R e s t a r t L a u n c h e r . j a v a : 49 ) C a u s e d b y : j a v a . l a n g . I l l e g a l S t a t e E x c e p t i o n : A m b i g u o u s m a p p i n g . C a n n o t m a p ′ w h i t e L i s t C o n t r o l l e r ′ m e t h o d p u b l i c c o m . t r i t o n s f s . c o r e . b e a n . R e s p o n s e B e a n c o m . t r i t o n s f s . c o n t r o l l e r . W h i t e L i s t C o n t r o l l e r . i n s e r t ( j a v a x . s e r v l e t . h t t p . H t t p S e r v l e t R e q u e s t ) t o [ / a p i / l i s t / i n s e r t ] , m e t h o d s = [ P O S T ] : T h e r e i s a l r e a d y ′ b l a c k L i s t C o n t r o l l e r ′ b e a n m e t h o d p u b l i c c o m . t r i t o n s f s . c o r e . b e a n . R e s p o n s e B e a n c o m . t r i t o n s f s . c o n t r o l l e r . B l a c k L i s t C o n t r o l l e r . i n s e r t ( j a v a x . s e r v l e t . h t t p . H t t p S e r v l e t R e q u e s t ) m a p p e d . a t o r g . s p r i n g f r a m e w o r k . w e b . s e r v l e t . h a n d l e r . A b s t r a c t H a n d l e r M e t h o d M a p p i n g 0(AbstractBeanFactory.java:317) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:760) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:869) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550) at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759) at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:395) at org.springframework.boot.SpringApplication.run(SpringApplication.java:327) at com.tritonsfs.PayWebApplication.main(PayWebApplication.java:28) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) Caused by: java.lang.IllegalStateException: Ambiguous mapping. Cannot map 'whiteListController' method public com.tritonsfs.core.bean.ResponseBean com.tritonsfs.controller.WhiteListController.insert(javax.servlet.http.HttpServletRequest) to {[/api/list/insert],methods=[POST]}: There is already 'blackListController' bean method public com.tritonsfs.core.bean.ResponseBean com.tritonsfs.controller.BlackListController.insert(javax.servlet.http.HttpServletRequest) mapped. at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping 0(AbstractBeanFactory.java:317)atorg.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)atorg.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315)atorg.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)atorg.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:760)atorg.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:869)atorg.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550)atorg.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140)atorg.springframework.boot.SpringApplication.refresh(SpringApplication.java:759)atorg.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:395)atorg.springframework.boot.SpringApplication.run(SpringApplication.java:327)atcom.tritonsfs.PayWebApplication.main(PayWebApplication.java:28)atsun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethod)atsun.reflect.NativeMethodAccessorImpl.invoke(UnknownSource)atsun.reflect.DelegatingMethodAccessorImpl.invoke(UnknownSource)atjava.lang.reflect.Method.invoke(UnknownSource)atorg.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)Causedby:java.lang.IllegalStateException:Ambiguousmapping.CannotmapwhiteListControllermethodpubliccom.tritonsfs.core.bean.ResponseBeancom.tritonsfs.controller.WhiteListController.insert(javax.servlet.http.HttpServletRequest)to[/api/list/insert],methods=[POST]:ThereisalreadyblackListControllerbeanmethodpubliccom.tritonsfs.core.bean.ResponseBeancom.tritonsfs.controller.BlackListController.insert(javax.servlet.http.HttpServletRequest)mapped.atorg.springframework.web.servlet.handler.AbstractHandlerMethodMappingMappingRegistry.assertUniqueMethodMapping(AbstractHandlerMethodMapping.java:580)
at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping M a p p i n g R e g i s t r y . r e g i s t e r ( A b s t r a c t H a n d l e r M e t h o d M a p p i n g . j a v a : 544 ) a t o r g . s p r i n g f r a m e w o r k . w e b . s e r v l e t . h a n d l e r . A b s t r a c t H a n d l e r M e t h o d M a p p i n g . r e g i s t e r H a n d l e r M e t h o d ( A b s t r a c t H a n d l e r M e t h o d M a p p i n g . j a v a : 265 ) a t o r g . s p r i n g f r a m e w o r k . w e b . s e r v l e t . h a n d l e r . A b s t r a c t H a n d l e r M e t h o d M a p p i n g . l a m b d a MappingRegistry.register(AbstractHandlerMethodMapping.java:544) at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.registerHandlerMethod(AbstractHandlerMethodMapping.java:265) at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.lambda MappingRegistry.register(AbstractHandlerMethodMapping.java:544)atorg.springframework.web.servlet.handler.AbstractHandlerMethodMapping.registerHandlerMethod(AbstractHandlerMethodMapping.java:265)atorg.springframework.web.servlet.handler.AbstractHandlerMethodMapping.lambdadetectHandlerMethods$1(AbstractHandlerMethodMapping.java:250)
at java.util.LinkedHashMap.forEach(Unknown Source)
at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.detectHandlerMethods(AbstractHandlerMethodMapping.java:248)
at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.initHandlerMethods(AbstractHandlerMethodMapping.java:218)
at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.afterPropertiesSet(AbstractHandlerMethodMapping.java:188)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping.afterPropertiesSet(RequestMappingHandlerMapping.java:129)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1765)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1702)
… 19 more

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 这是一个Spring Boot的错误信息,具体是关于创建名为'requestmappinghandlermapping'的bean时出现了问题。这个bean是在类路径资源[org/springframework/boot/autoconfigure/web/servlet/webmvcautoconfiguration$enablewebmvcconfiguration.class]中定义的。 ### 回答2: 该错误通常是因为Spring容器无法创建请求映射处理程序映射bean。这通常是由于以下原因之一引起的: 1.类路径上缺少所需的依赖项。Spring需要许多依赖项才能正确地创建请求映射处理程序映射bean。如果其中一个依赖项不可用,则会导致创建bean时出现错误。 2.请求映射处理程序映射bean的配置中出现错误。如果在配置请求映射处理程序映射bean时出现任何错误,例如错误的属性名称或值,则可能会导致创建bean时出现错误。 3.请求映射处理程序映射bean所依赖的其他bean无法创建。如果请求映射处理程序映射bean依赖于另一个bean,并且该bean无法成功创建,那么请求映射处理程序映射bean也将失败。 要解决此错误,可以尝试使用以下步骤: 1.根据错误信息检查缺少的依赖项。 2.检查请求映射处理程序映射bean的配置文件,并确保所有属性名称和值都正确。 3.检查bean依赖项,以确保它们正确创建。 4.在配置文件中添加更多日志记录,以便更好地了解程序的运行情况。 5.最后,如果以上解决方案都无效,可能需要寻求专业开发人员的帮助,以深入了解错误的原因并解决问题。 ### 回答3: Spring框架在进行工厂实例化时,要求所有的Bean对象必须拥有一个默认构造函数,否则就会抛出BeanCreationException异常。这个错误通常是由于在创建Bean对象时抛出了异常,而在这个异常中,发现了一个名为'requestmappinghandlermapping'的Bean被定义在了类路径资源文件中。 具体来说,这个错误通常出现在Web开发时,通过SpringBoot启动Web服务器时。它在启动时动态创建了一些组件,包括RequestMappingHandlerMapping,它是SpringMVC框架的一个重要组件,负责将请求映射到对应的处理器方法。 在创建这个组件时,如果Spring框架出现了异常,就会抛出这个BeanCreationException错误。可能的原因包括缺少必需的依赖项、组件注解不正确、组件的依赖关系循环依赖等等。 要解决这个问题,可以首先检查相关的依赖项是否正确配置,例如是否导入了必需的组件等。同时,可以检查组件的注解是否正确、是否存在循环依赖等。另外,可以尝试使用SpringBoot提供的调试工具或者日志记录来定位错误并解决它。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值