简体   繁体   English

覆盖子Spring Controller中的@RequestMapping

[英]Override @RequestMapping in child Spring Controller

We use Spring 3.2 for our projects with a parent and child (maven) projects (child project extends the parent project). 我们将Spring 3.2用于具有父项和子项(maven)项目的项目(子项目扩展了父项目)。

We have an issue to override the @RequestMapping in the child project to redefine specifically the state of an URL. 我们有一个问题是覆盖子项目中的@RequestMapping以专门重新定义URL的状态。 For example : 例如 :

@Controller
public class MyParentProjectController {

    @RequestMapping(value = "/pdfRender")
    public ModelAndView pdfRender(MyParentProjectCommand command, HttpServletRequest request,
            HttpServletResponse response, Application application)
        {
            // ...
        }
    }
}

And in the child project with a dependency on the parent project : 并且在子项目中依赖于父项目:

@Controller
public class MyChildProjectController {

    @RequestMapping(value = "/pdfRender")
    public ModelAndView pdfRender(MyChildProjectCommand command, HttpServletRequest request,
            HttpServletResponse response, Application application)
        {
            // ...
        }
    }
}

Spring tells me it's impossible because there are two identical entry points in the child project. Spring告诉我这是不可能的,因为子项目中有两个相同的入口点。 It's not possible to redefine a RequestMapping . 无法重新定义RequestMapping I do not find a solution to do that without going through twisted stuff. 没有经过扭曲的东西,我找不到解决办法。 If you have a brilliant solution for me without use @RequestMapping(value="${...}") . 如果您在没有使用@RequestMapping(value="${...}")情况下为我提供了出色的解决方案。

Best regards 最好的祝福

I'd make the parent an abstract class and leave that method unimplemented to override it. 我将父类作为一个抽象类,并使该方法未实现以覆盖它。

If you want to have it that way, this workaround may help you; 如果你想这样做,这种解决方法可能对你有帮助; check out the SpringMVC router project on GitHub . 在GitHub上查看SpringMVC路由器项目

It's an implementation of Play's Routes file for SpringMVC. 这是SpringMVC的Play's Routes文件的实现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM