发现当我用暧昧的映射扩展条款 [英] Ambiguous mapping found when I use extends clause
问题描述
我有一个 CustomerController 和 CustomerCardController 类扩展的 CrudMethods 类。
I have a CustomerController and CustomerCardController classes that extend CrudMethods class.
我选择的话,因为这两个控制器使用相同的方法(getFileCustomer()是其中之一)。而且我认为它已经最好使用继承节省code的行。
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.
CustomerController
@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
消息:内部服务器错误
说明:服务器遇到一个内部错误prevented
它满足了这一请求。
description: The server encountered an internal error that prevented it from fulfilling this request.
例外:
javax.servlet.ServletException:Servlet.init()进行servlet调度
抛出异常
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)
此请求映射是在两个present CustomerCardController
和 CustomerController
类,因为它们扩展有这种映射相同的类。所以,你必须为同一请求映射重复的条目。
@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.
这篇关于发现当我用暧昧的映射扩展条款的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!