web-services - spring boot部署外部tomcat

标签 web-services maven tomcat spring-boot web-deployment

我正在使用 spring boot 和一个简单的 hello world Controller 。我想将它部署到外部 tomcat 服务器。我注意到 web.xml 文件丢失了。我希望在 web-inf 目录中看到这个文件。 在内部运行 spring boot 时(使用 spring boot 的内部 tomcat,它可以工作。但我想将我的应用程序部署到外部 tomcat 服务器。

将 war 文件部署到外部 tomcat 服务器后,我可以在可用服务列表中看到 hello world,但我无法使用 hello world 服务 - 我收到 404 错误消息。

我正在使用 maven、Jdk 1.8、IntelliJ

这是我的 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-spring-boot</artifactId>
<version>0.1.0</version>
<packaging>war</packaging>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.3.1.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>
    <dependency>
        <groupId>org.apache.maven</groupId>
        <artifactId>maven-plugin-api</artifactId>
        <version>3.3.9</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-jpa</artifactId>
        <version>1.9.2.RELEASE</version>
    </dependency>

</dependencies>

<properties>
    <java.version>1.8</java.version>
</properties>


<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
        <plugin>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.6</version>
            <configuration>
                <attachClasses>true</attachClasses>
            </configuration>
        </plugin>
    </plugins>
</build>

</project>

这是我的应用程序类:

import java.util.Arrays;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.web.SpringBootServletInitializer;
import org.springframework.context.ApplicationContext;

@SpringBootApplication
public class Application extends SpringBootServletInitializer {

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

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

        System.out.println("Let's inspect the beans provided by Spring Boot:");

        String[] beanNames = ctx.getBeanDefinitionNames();
        Arrays.sort(beanNames);
        for (String beanName : beanNames) {
            System.out.println(beanName);
        }
    }
}

将 hello world 应用程序部署到外部 tomcat 服务的正确方法是什么?

最佳答案

在 tomcat 上部署时,应该有一个由容器添加的上下文路径,并且必须作为第一个元素路径包含在您的 URL 中。检查 tomcat 启动日志以获取上下文路径并按指示重试调用服务。

关于web-services - spring boot部署外部tomcat,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34405318/

相关文章:

c# - 如何使用 IAsyncResult 从 WCF 异步中的回调中抛出异常

java - Eclipse/Maven : "Could not find the main class" Errors While Building Executable JAR

java - 在 Eclipse 中启动一个简单的 Maven 项目的问题?

Apache /Tomcat/Railo : Setting up two sites with same domain but two different ports

c# - 如何从 ASMX Web 服务返回错误?

c++ - 使用 C++ 通过 SOAP 连接到 TFS

java - 如何解决 joda-time 和 org.joda 之间的包冲突

eclipse - PrimeFaces 登录尝试(示例)失败

java - 自定义 servlet 在 Tomcat 6 上给出 404,在 7 上工作正常

java - 使用 Web 服务的 Android Mssql 服务器