【问题标题】:Handle two dispatcher Servlets using AbstractAnnotationConfigDispatcherServletInitializer使用 AbstractAnnotationConfigDispatcherServletInitializer 处理两个调度程序 Servlet
【发布时间】:2018-02-19 08:08:30
【问题描述】:

我正在尝试配置 spring maven 多模块项目。我在两个子 web 模块中有two dispatcher 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 A 中导入module B 时,因为两者都是war 文件,我无法访问Bar.classModule AWeb application with UIModule BREST API

那么,有没有办法在单个 application Context 中同时配置两者,或者我需要为 REST 模块创建另一个应用程序上下文?

如果您需要任何信息,请告诉我。

【问题讨论】:

    标签: java spring maven spring-mvc servlets


    【解决方案1】:

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

    Module A

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

    【讨论】:

    • 这就是我所做的。但是由于module Awar文件所以其他Servlet ConfigurationModule B中不可见
    • 必须在 ModuleA 中导入 ModuleB。我假设你的 moduleB 生成 jar 文件。
    • 实际上module b 是一个war 可悲
    猜你喜欢
    • 1970-01-01
    • 2015-10-04
    • 1970-01-01
    • 2023-04-06
    • 2017-12-12
    • 2014-05-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多