Home > Software engineering >  Spring Boot module as a dependency gets started as its own app when in a war
Spring Boot module as a dependency gets started as its own app when in a war

Time:12-05

My application is structured as such:

  • root
    • module 1 (pure classes)
    • module 2 (spring boot app) -> has module 1 as a dependency
    • module 3 (sprint boot app) -> has module 2 as a dependency

When I package module 3 as a war and deploy it on tomcat, for some reason the module 2 app also starts up. I only want to use the module 2 classes in module 3, and not have the Spring app start up from module 2.

I package module 2 using the maven-war plugin:

            <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <version>3.2.3</version>
                <configuration>
                    <attachClasses>true</attachClasses>
                    <classesClassifier>classes</classesClassifier>
                </configuration>
            </plugin>

and import the jar in module 3 via:

        <dependency>
            <groupId>com.company</groupId>
            <artifactId>module2<artifactId>
            <version>1.0.0-SNAPSHOT</version>
            <scope>compile</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-tomcat</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

I have tried using the spring boot plugin to package as well, but I am unable to prevent the module 2 application from starting in module 3.

CodePudding user response:

I would think the best solution (even though it might take some rework) separate module 2 into two separate modules, one for the core classes and another for the application. Then module 3 can easily import module 2 classes as the module 2 application is no longer in there.

If this isn't an option then you will need to define the main class in the pom file when building your war file config. See this related link: Using Maven to create "runnable WAR"

  • Related