Using Spring Boot Web Application with Pivotal TC Server

南笙酒味 提交于 2019-12-04 23:16:33

You can deploy a Spring Boot application to tc Server in the same way that you'd deploy it to any other standalone servlet container. There are three changes that you need to make:

  1. Extend SpringBootServletInitializer so that the container will bootstrap your application correctly:

    @Configuration
    @EnableAutoConfiguration
    @ComponentScan
    public class Application extends SpringBootServletInitializer {
    
        @Override
        protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
            return application.sources(Application.class);
        }
    }
    
  2. Convert the project to use war packaging. Maven example:

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <!-- ... -->
        <packaging>war</packaging>
        <!-- ... -->
    </project>
    
  3. Mark your spring-boot-starter-tomcat dependency as provided so that embedded Tomcat doesn't conflict with the classes in tc Server. Maven example:

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
        <scope>provided</scope>
    </dependency>
    

I'm not aware of any differences between the class-reloading capabilities of Tomcat and tc Server. Perhaps you have Spring Loaded configured in your tc Server instance? If so, you can use it with Spring Boot too.

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