首页 文章

Spring Boot用于部署/包装传统的基于Spring的战争

提问于
浏览
0

我有一个使用Spring的遗留Web应用程序 . 到目前为止,战争已部署在预先安装的tomcat容器的 生产环境 中 . tomcat容器将创建一个JNDI,该应用程序使用JNID连接到DB .

现在我希望使用spring boot和嵌入式tomcat包装这个遗留应用程序 .

我相信会创建2个应用程序上下文:一个是Spring Boot,另一个是使用Spring的遗留应用程序 .

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

此外,我仍然希望在spring boot嵌入式tomcat中创建JNDI并与遗留应用程序共享 .

顺便说一下,我试图使用这里提供的spring boot tomcat jndi样本:https://github.com/wilkinsona/spring-boot-sample-tomcat-jndi

使用Spring Boot包装服务的原因是创建Docker容器以与多个团队共享 .

1 回答

  • -1

    使用Spring Boot“wrapper”包装现有WAR,以便不必重新配置现有代码库 . 将其添加到您的代码中 .

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

    使用maven-dependency-plugin并设置spring-boot-maven-plugin以从资源中排除WAR文件(否则你将获得Spring Boot WAR中包含的两个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>
    

相关问题