使用Maven多模块项目进行Spring Boot [英] Spring boot with maven multi module project
问题描述
我有一个Maven多模块项目,其设计类似于以下SO帖子中的第一个答案: 带有Spring Boot的多模块Maven
I have a maven multi module project designed like the first answer in following SO post: Multi-module maven with Spring Boot
现在,我需要一个通用的Maven模块,其中可以包含多个微服务要使用的模型.如果我将这个公共项目作为一级父pom的子项进行创建(这样,由启动注入的所有依赖项(例如jpa,jackson等)都可以使用),那么STS/Spring会将其检测为启动应用程序,并且抱怨没有Main关于Maven构建的课程.
Now I want a common maven module that can contain some models to be used by multiple microservices. If I make this common project as a child of the first level parent pom (so that all dependencies injected by boot like jpa, jackson etc are available to common), then STS/Spring is detecting it as a boot application and complains about no Main class on maven build.
有人可以建议我如何实现这一目标吗?
Can someone suggest how I can achieve this?
当前代码:
父pom.xml:(仅包括相关部分)
parent pom.xml: (Only relevant parts included)
<project>
<name>...</name>
<groupId>...</groupId>
<artifactId>...</artifactId>
<packaging>pom</packaging>
<version>...</version>
<parent>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-parent</artifactId>
<version>Brixton.M3</version>
<relativePath />
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jetty</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
子(公共模块)pom.xml(仅相关部分),而不是引导应用程序:
child (common module) pom.xml (only relevant parts), not to be boot app:
<project>
<artifactId>...</artifactId>
<version>...</version>
<name>...</name>
<parent>
<groupId>...</groupId>
<artifactId>...</artifactId>
<version>...</version>
</parent>
</project>
推荐答案
我没有关于您的项目的所有详细信息,但我最好的猜测是spring-boot-maven-plugin
是在父项上定义的(或者您正在使用spring-boot-starter-parent
在您的根pom中).这有效地要求构建将模块打包为Spring Boot应用程序(这不是您想要的).
I don't have all the details regarding your project but my best guess is that the spring-boot-maven-plugin
is defined on the parent (or you are using the spring-boot-starter-parent
in your root pom). This effectively ask the build to package your module as a Spring Boot app (which is not what you want).
STS可能会寻找该提示,以找出模块是否包含Spring Boot应用程序.如果它寻找带有@EnableAutoConfiguration
(或SpringBootApplication
)注释的主类,也许会更好.
STS probably looks for that hint to figure out if a module contains a Spring Boot application or not. Maybe it would be nicer if it looks for a main class annotated with @EnableAutoConfiguration
(or SpringBootApplication
).
通过指定如果STS仍将模块作为Spring Boot应用程序使用,我将在其跟踪器中创建问题
If STS still picks up the module as a Spring Boot app, I'd create an issue in their tracker
这篇关于使用Maven多模块项目进行Spring Boot的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!