必须仅在子模块中添加spring-boot-starter-*依赖项



我有一个父模块(A(,它已经作为依赖项包含/导入到子模块(B(中。

模块A

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>*some-version*<version>
</dependency>
<dependencies>

模块B

<dependencies>
<dependency>
<groupId>com.xyz</groupId>
<artifactId>module-A</artifactId>
<version>*module-A-version*<version>
</dependency>
<dependencies>

问题:编译中没有错误,模块B(B.war(的war工件已成功创建。但当我部署模块B(即B.war(时,它会因以下错误而失败。

线程中的异常"主";java.lang.NoClassDefFoundError:org/springframework/beans/factory/config/YamlProcessor位于java.lang.ClassLoader.defineClass1(本机方法(位于java.lang.ClassLoader.defineClass(ClassLoader.java:763(位于java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142(位于java.net.URLClassLoader.defineClass(URLClassLoader.java:467(位于java.net.URLClassLoader.access$100(URLClassLoader.java:73(位于java.net.URLClassLoader$1.run(URLClassLoader.java:368(位于java.net.URLClassLoader$1.run(URLClassLoader.java:362(位于java.security.AccessController.doPrivileged(本机方法(位于java.net.URLClassLoader.findClass(URLClassLoader.java:361(位于java.lang.ClassLoader.loadClass(ClassLoader.java:424(在sun.mic.Launcher$AppClassLoader.loadClass(Launcher.java:331(位于java.lang.ClassLoader.loadClass(ClassLoader.java:357(位于org.springframework.boot.env.YamlPropertySourceLoader.load(YamlPropertySource Loader.java:57(位于org.springframework.boot.env.PropertySourcesLoader.load(PropertySourcesLoader.java:127(位于org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.loadIntoGroup(ConfigFileApplicationLister.java:462(位于org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.load(ConfigFileApplicationLister.java:449(位于org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.load(ConfigFileApplicationLister.java:374(位于org.springframework.boot.context.config.ConfigFileApplicationListener.addPropertySources(ConfigFileApplicationLister.java:210(位于org.springframework.boot.context.config.ConfigFileApplicationListener.postProcessEnvironment(ConfigFileApplicationLister.java:179(位于org.springframework.boot.context.config.ConfigFileApplicationListener.onApplicationEnvironmentPreparedEvent(ConfigFileApplicationLister.java:166(位于org.springframework.boot.context.config.ConfigFileApplicationListener.onApplicationEvent(ConfigFileApplicationLister.java:152(位于org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMultiaster.java:163(网址:org.springframework.context.event.SimpleApplicationEventMulticast.multcastEvent(SimpleApplicationEventMultiaster.java:136(网址:org.springframework.context.event.SimpleApplicationEventMulticast.multcastEvent(SimpleApplicationEventMultiaster.java:119(位于org.springframework.boot.context.event.EventPublishingRunListener.publishEvent(EventPublishingRunLister.java:111(位于org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunLister.java:65(网址:org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:54(网址:org.springframework.boot.SpringApplication.doRun(SpringApplication.java:325(网址:org.springframework.boot.SpringApplication.run(SpringApplication.java:305(网址:org.springframework.boot.SpringApplication.run(SpringApplication.java:1124(网址:org.springframework.boot.SpringApplication.run(SpringApplication.java:1113(网址:com.propspace.intl.gateway.GatewayInternational.main(GatewayInternational.java:32(引起原因:java.lang.ClassNotFoundException:org.springframework.beans.factory.config.YamlProcessor位于java.net.URLClassLoader.findClass(URLClassLoader.java:381(位于java.lang.ClassLoader.loadClass(ClassLoader.java:424(在sun.mic.Launcher$AppClassLoader.loadClass(Launcher.java:331(位于java.lang.ClassLoader.loadClass(ClassLoader.java:357(…还有32个

是不是我们总是必须在叶模块中包含spring-boot-starter-*,而它不能在一个通用的父级中定义?

在对pom启动器进行了几次PoC之后,确认只有deployable服务应该在其pom.xml中定义相应的pom启动器。

因此,层次结构之上的w.r.t子级B必须具有如下定义,

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>*some-version*<version>
</dependency>
<dependencies>

父级A可以包含任何其他不是pom启动器的常见依赖项。

最新更新