Spring 具有单个 war 文件的多模块项目,其中所有模块仅依赖于公共模块

Spring Multi Module project with single war file where all modules depends only on common module

我正在将现有的 spring 项目拆分为多模块项目,其中每个模块仅依赖于公共模块并创建一个 jar 文件,除了最后一个创建 war 文件。

这是项目结构

parent        - packaging -POM, defines module sequence 
common_mod    - common java code i.e. interface , base classes
jar-Mod-1     - depends on common
jar-Mod-2     - depends on common
jar-Mod-3     - depends on common
war-Mod       - depends only on common, this contains java and webapp code

每个项目都有自己的 spring 背景。最后一个模块导入它们中的每一个,例如

<import resource="classpath*:common-config.xml"/>

现在我想创建单个 war,其中包含所有模块的 jar,但不将每个模块定义为最终 war 模块中的依赖项。如果我指定相同,那么开发人员也可以在 war 模块中编写模块特定代码(比如 Jar Mod 1 模块),我想避免这种情况。

现在,当我创建 war 时,它只包含公共模块的 jar,因为它被指定为 war 模块中的依赖项。

所以当我 运行 这个项目时,它抱怨说没有从其他模块中找到 bean,这很明显,因为 war 不包含其他模块的 jar。

感谢 Artem Bilan 的回答,

你将在war模块中添加模块依赖,但是如果你想在编译时忽略它们,但需要在最终WAR中使用该模块的jar(这正是我想要的),您必须将该依赖项的范围定义为 runtime.

Maven : what is the "runtime" scope purpose?