tomcat - 在 Tomcat 上部署 Spring Boot war 文件

标签 tomcat deployment spring-boot war

我将 Spring Boot 1.2.4.RELEASE 与 gs-rest-service 一起使用源文件。 我得到了:

127.0.0.1 - - [18/Jun/2015:09:59:25 +0300] "GET /gs-rest-service-0.1.0/ HTTP/1.1" 404 1021

Tomcat 日志中没有其他异常。

我已阅读相关问题,但我的测试没有运行。 Spring Boot War deployed to Tomcat

我已阅读 howto-create-a-deployable-warPackaging executable jar and war files .

也许我错过了什么。

我的来源:

1.pom.xml

<?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">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.springframework</groupId>
    <artifactId>gs-rest-service</artifactId>
    <version>0.1.0</version>
    <packaging>war</packaging>

    <properties>        
        <start-class>hello.Application</start-class>
        <java.version>1.8</java.version>
    </properties>


    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.2.4.RELEASE</version>
    </parent>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

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

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <showDeprecation>true</showDeprecation>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <repositories>
        <repository>
            <id>spring-releases</id>
            <url>https://repo.spring.io/libs-release</url>
        </repository>
    </repositories>
    <pluginRepositories>
        <pluginRepository>
            <id>spring-releases</id>
            <url>https://repo.spring.io/libs-release</url>
        </pluginRepository>
    </pluginRepositories>
</project>

2.Application.java

package hello;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.web.SpringBootServletInitializer;

@SpringBootApplication
public class Application extends SpringBootServletInitializer {

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(Application.class);
    }

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

文件 Greeting.java 和 GreetingController.java 没有改变。

最佳答案

刚刚在这里试过了,可以重现完全相同的行为。

听起来很愚蠢,很可能您在 Java 1.7 JRE(推测)下运行外部 tomcat,同时针对 1.8 编译了您的代码(我们从您的 pom 中知道这一点)。

奇怪的是,没有错误,应用程序出现在管理器应用程序中,但是当您尝试访问它时会收到 404。

确认这一点的一种方法是查看您的 tomcat 日志输出。你看到 Spring Boot 横幅了吗?可能不是。

关于tomcat - 在 Tomcat 上部署 Spring Boot war 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30908579/

相关文章:

c# - 部署 winforms 应用程序

spring-boot - 使用 Spring Boot Micrometer 指标显示 HTTP 请求 API 延迟

java - 如何从cmd永久增加芝麻存储的堆大小?

java - 使用 eclipse 和 Tomcat 问题调试 Spring MVC

c++ - C++ 项目的 Ubuntu 部署问题

spring - Cognito 自定义消息并包含用户属性

spring-boot - 远程连接到PCF云配置服务器服务

mysql - 在 Tomcat 应用程序的 Maven 构建期间找不到 web.xml

tomcat - 在 servlet 应用程序中保存上传文件的推荐方法

javascript - NodeJS 应用程序使用 Heroku 构建,但显示应用程序错误