使用AbstractAnnotationConfigDispatcherServletInitializer处理两个调度程序Servlet

时间:2017-09-11 06:46:12

标签: java spring maven spring-mvc servlets

我正在尝试配置spring maven multimodule项目。我在两个子 web 模块中有two个调度程序Servlets(比如Foo {Module A},Bar {Module B})。我要做的就是配置所有单个root context,并说它在模块A中并且使用spring AbstractAnnotationConfigDispatcherServletInitializer我正在配置

AppContext extends AbstractAnnotationConfigDispatcherServletInitializer{
@Override
    protected Class<?>[] getRootConfigClasses() {
        return new Class[] { ... };
    }

    @Override
    protected Class<?>[] getServletConfigClasses() {
        return new Class[] { Foo.class, Bar.class* }; //Bar.class Desired but not getting
    }

    @Override
    protected String[] getServletMappings() {
        return new String[] { "/" };
    }
}

现在问题是我在module B内导入module A,因为两者都是war文件而我无法访问Bar.classModule AWeb application with UIModule BREST API

那么,有没有办法在单个application Context内配置,或者我是否需要为REST模块创建另一个应用程序Context?

如果您需要任何信息,请知道。

1 个答案:

答案 0 :(得分:3)

您可以使用maven多模块功能。

模块A

的pom.xml中添加以下代码
<modules>
    <module>**artifactId of module B**</module>     
</modules>