404将tom部署到tomcat时

时间:2017-10-02 20:15:34

标签: java spring maven tomcat war

我有一个Spring Boot应用程序,我想部署到Tomcat。但是,当我将它部署到tomcat并访问api / users / all时,我得到了404.有什么帮助吗?

这是我的pom:

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

http://maven.apache.org/xsd/maven-4.0.0.xsd“&GT;     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文件。据我了解,我不需要一个,对吗?

提前致谢!

1 个答案:

答案 0 :(得分:1)

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

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