0
votes

I have a legacy web application that makes use of Spring. Till now the war is deployed in production on a pre installed tomcat container. The tomcat container will create a JNDI and The application makes use of JNID to connect to DB.

Now i want wrap this legacy application war using the spring boot and embedded tomcat.

I believe there will be 2 application context created: One by Spring Boot and One by the legacy application using Spring .

What is the best way to wrap this legacy war application using Spring boot?

Also i still want to create the JNDI in the spring boot embedded tomcat and share it with the legacy application.

By the way i was trying to use the spring boot tomcat jndi sample available here: https://github.com/wilkinsona/spring-boot-sample-tomcat-jndi

The reason for wrapping the service with Spring Boot is to create Docker containers to share with multiple teams.

1
You can use a regular Tomcat within Docker. That is easier than just "wrapping" a legacy Spring application within Spring Boot application (which i don't think is possible at all, already because of dependency versions etc.). - dunni
@dunni, Yes! finally i took this approach and wrapped my legacy war within a tomcat container using the tomcat docker image tomcat:7.0.79-jre7-alpine - Naveen Kumar

1 Answers

-1
votes

To wrap an existing WAR with a Spring Boot "wrapper" so that the existing code base doesn't have to be reconfigured. Add this to your code.

 Context context = tomcat.addWebapp("myapp", Thread.currentThread().getContextClassLoader().getResource("myapp.war").g
etPath());

use the maven-dependency-plugin and set the spring-boot-maven-plugin to exclude the WAR file from the resources (otherwise you get two copies of the WAR included in your Spring Boot WAR):

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <version>3.0.0</version>
    <executions>
        <execution>
            <id>copy-dependencies</id>
            <phase>generate-resources</phase>
            <goals>
                <goal>copy-dependencies</goal>
            </goals>
            <configuration>
                <excludeTransitive>true</excludeTransitive>
                <includeArtifactIds>my-war-name-here</includeArtifactIds>
                <stripVersion>true</stripVersion>
                <outputDirectory>${project.basedir}/src/main/resources</outputDirectory>
            </configuration>
        </execution>
    </executions>
</plugin>


<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <version>1.5.3.RELEASE</version>
    <executions>
        <execution>
            <goals>
                <goal>repackage</goal>
            </goals>
            <configuration>
                <!-- Don't copy the war as a dependency, it's included as a resource -->
                <excludeArtifactIds>my-war-name-here</excludeArtifactIds>
            </configuration>
        </execution>
    </executions>
</plugin>