警告: Exception encountered during context initialization - cancelling refresh attempt

错误详情

警告: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping': Invocation of init method failed; nested exception is java.lang.IllegalStateException: Ambiguous mapping. Cannot map 'BookContorller' method 
com.contorller.BookContorller#list(Model)
to { [/books/listAll]}: There is already 'bookContorller' bean method
com.contorller.BookContorller#list(Model) mapped.

 提示原因指出:Controller中出现重复url,但是代码中没有重复

 错误原因

xml文件中配置的bean id 为大写开头

 根本原因

当@Controller未指定value值时,默认创建bean id 为小写开头的类名

然而又在xml文件中显示配置了大写开头id的bean,导致出现有相同url的bean

一个为bookContorller,注解所创建的

一个为BookContorller,xml文件显示创建

解决方法

将@Controller创建的bean的id与xml文件中指定的id改为相同

建议

在spring中配置Controller时,不要在一个bean中同时使用注解和xml显示配置,不然容易触发上述问题

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值