将Spring Boot Web应用程序与Pivotal TC Server一起使用 [英] Using Spring Boot Web Application with Pivotal TC Server

查看:170
本文介绍了将Spring Boot Web应用程序与Pivotal TC Server一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从Spring Tool Suite内部将项目重构为Spring Boot应用程序.所有文档都显示了如何使用嵌入式Tomcat实例创建一个自包含的应用程序,该实例有效且出色.

I refactored my project as a Spring Boot application from inside Spring Tool Suite. All the documentation shows how to create a self contained application with an embedded Tomcat instance which works and is great.

但是,在此之前,我有自己的Maven Web-MVC项目,该项目具有针对Spring的基于XML的配置.我可以将其直接部署到TC Server,并且效果很好.我最喜欢的是:热插拔!我可以添加新的函数和类,它们会立即由TC Server接收,而无需进行任何其他配置.

Before this however I had my own Maven Web-MVC project with XML-based configuration for Spring. I could deploy this directly to TC Server and it worked great. What I like most: Hot Swapping! I could add new functions and classes and they immediately were picked up by TC Server without any additional configuration.

但是,使用Spring Boot和嵌入式Tomcat,我发现情况并非如此.热插拔非常有限,并且需要进行许多基本更改才能重新启动.根据我一直在阅读的内容,TC Server是Tomcat的更复杂的版本,因此这引出了我的两个问题:

Using Spring Boot and embedded Tomcat, however, I've found this is not the case. Hotswapping is very limited and a restart is required for a lot of basic changes. From what I've been reading TC Server is a much more sophisticated version of Tomcat so this leads me to my two questions:

1)如何使我的Maven Spring Boot应用程序通过STS在TC Server上运行?启动新的Pivotal TC运行配置对我不起作用.

1) How do I get my Maven Spring Boot application running on TC Server via STS? Starting a new Pivotal TC Run Configuration is not working for me.

2)当前者看起来更好用时,为什么Spring Boot文档示例不强调在嵌入式Tomcat上使用TC Server?

2) Why don't Spring Boot documentation examples emphasize usage of TC Server over the embedded Tomcat when the former appears to work so much better?

推荐答案

您可以将Spring Boot应用程序部署到tc Server,就像将其部署到任何其他独立servlet容器一样.您需要进行三项更改:

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. 扩展SpringBootServletInitializer,以便容器正确引导您的应用程序:

  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);
    }
}

  • 将项目转换为使用war包装. Maven示例:

  • 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>
    

  • 标记提供的spring-boot-starter-tomcat依赖项,以使嵌入式Tomcat与tc Server中的类不冲突. Maven示例:

  • 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>
    

  • 我不知道Tomcat和tc Server的类重载功能之间是否存在任何差异.也许您在tc Server实例中配置了Spring Load?如果是这样,您也可以在Spring Boot中使用它.

    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.

    这篇关于将Spring Boot Web应用程序与Pivotal TC Server一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆