我有一个我想部署到Tomcat的spring boot应用程序。但是,当我将其部署到tomcat并访问api / users / all时,我会得到404。有什么帮助吗?

这是我的pom:

<?xml version="1.0" encoding="UTF-8"?>


http://maven.apache.org/xsd/maven-4.0.0.xsd“>
    4.0.0

<groupId>be.pxl</groupId>
<artifactId>api</artifactId>
<version>0.1.0</version>

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

<packaging>war</packaging>

<properties>
    <java.version>1.8</java.version>
    <start-class>be.pxl.mdev.Application</start-class>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.36</version>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>




这是我的主要应用程序开始:

package be.pxl.mdev;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class Application {

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


}

我没有web.xml或manifest.mf文件。据我了解,我不需要一个,对吗?

提前致谢!

最佳答案

将此方法添加到您的Application类中,Application需要扩展SpringBootServletInitializer

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

07-27 13:23