使用 extends 子句时发现不明确的映射 [英] Ambiguous mapping found when I use extends clause

查看:26
本文介绍了使用 extends 子句时发现不明确的映射的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 CustomerControllerCustomerCardController 类,它们扩展了 CrudMethods 类.

I have a CustomerController and CustomerCardController classes that extend CrudMethods class.

我选择这样,因为这两个控制器使用相同的方法(getFileCustomer() 就是其中之一).我认为最好使用继承来保存代码行.

I choose so, because these two controller use the same methods (getFileCustomer() is one of these). And I thought that it had been better use the inheritance to save code's rows.

客户控制器

@Controller
public class CustomerController extends CrudMethods {
...

CustomerCardController

@Controller
public class CustomerCardController extends CrudMethods{
...

CrudMethos

@Controller
public abstract class CrudMethods {

@RequestMapping("getFileCustomer")
@ResponseBody
public String getFileCustomer() {
...

当我运行时,GlassFish 给我这个错误:

When I run, GlassFish gives me that error:

HTTP 状态 500 - 内部服务器错误类型异常报告

HTTP Status 500 - Internal Server Error type Exception report

消息:内部服务器错误

描述:服务器遇到内部错误,阻止它来自于满足这个请求.

description: The server encountered an internal error that prevented it from fulfilling this request.

例外:

javax.servlet.ServletException: servlet 调度程序的 Servlet.init()抛出异常

javax.servlet.ServletException: Servlet.init() for servlet dispatcher threw exception

根本原因:发现不明确的映射

root cause: Ambiguous mapping found

问题是@RequestMapping 和@ResponseBody 注释.

The problems are @RequestMapping and @ResponseBody annotations.

事实上,如果我删除它们,应用程序就会启动.

In fact, if I remove them the application starts.

但我需要这些注释.因为,@RequestMapping 和@ResponseBody 在应用程序运行时被 Ajax 调用使用.

But I need of these annotation. Because, the @RequestMapping and @ResponseBody are used by Ajax call when the application runs.

两个控制器中都使用了 getFileCustomer().

And getFileCustomer() is used in both of controllers.

如何解决?

谢谢

推荐答案

@RequestMapping("getFileCustomer") 这个请求映射同时存在于 CustomerCardControllerCustomerController 类,因为它们扩展了具有此映射的相同类.所以你有相同请求映射的重复条目.

@RequestMapping("getFileCustomer") this request mapping is present in both CustomerCardController and CustomerController class since they extend same class which has this mapping. So you have duplicate entry for same request mapping.

这篇关于使用 extends 子句时发现不明确的映射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆