Spring boot with maven multi module project

梦想与她 提交于 2019-12-04 07:23:36

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 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).

You can fix the problem easily (from the build side) by specifying the skip property of the repackage goal

  <plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <configuration>
          <skip>true</skip>
    </configuration>
  </plugin>

If STS still picks up the module as a Spring Boot app, I'd create an issue in their tracker

Normally, Spring Boot won't start a web container if it's not present in the module. I would suggest you to analyse your dendencies using the command

mvn dependency:tree 

One more brute-force way of ensuring is use this configuration in your application.properties

spring.main.web-environment=false
Arun Selvam

Here are two ways to fix this:

  1. You can add the skip property like @Stephane Nicoll mentioned. However, this will completely ignore the test cases inside that module. https://docs.spring.io/spring-boot/docs/current/maven-plugin/examples/it-skip.html
  2. Another option is to add a classifier property to make a separate executable jar out of this module. https://docs.spring.io/spring-boot/docs/current/maven-plugin/examples/repackage-classifier.html

    <executions>
              <execution>
                <id>repackage</id>
                <goals>
                  <goal>repackage</goal>
                </goals>
                <configuration>
                  <classifier>exec</classifier>
                </configuration>
              </execution>
    

This fix will make sure the dependent module get its required jar and the source module will still be an executable one.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!