【问题标题】:SpringBootServletInitializer not working on tomcat serverSpringBootServletInitializer 在 tomcat 服务器上不起作用
【发布时间】:2016-07-03 01:56:12
【问题描述】:

我正在尝试在本地 Tomcat 8 服务器上运行我的 Spring Boot 应用程序,但无法让它运行。它在 Eclipse 和 mvn spring-boot:run 中运行良好。

我添加了 SpringBootServletInitializer 并按照建议更改了 pom.xml。但它似乎永远不会运行。

这里是主类:

@SpringBootApplication
public class SasuApplication extends SpringBootServletInitializer {

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

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

}

这是我的 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>net.sverin.poc</groupId>
    <artifactId>sasu</artifactId>
    <version>1.0.0-SNAPSHOT</version>

    <packaging>war</packaging>

    <name>sasu</name>

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

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <java.version>1.8</java.version>
    </properties>

    <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>
        <finalName>sasu</finalName>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

我错过了什么?

【问题讨论】:

  • 无法运行是什么意思?什么错误?
  • 什么都没有发生...无法在 tomcat 日志中看到应用程序正在启动。完全没有春天的痕迹。以及所有 404 响应。
  • 尝试将@SpringBootApplication 类和Servletinit 类分开。像 ApplicationApplicationWebXml 这样的东西。

标签: spring-boot spring-boot-maven-plugin


【解决方案1】:

我知道的老问题,但我刚刚在 Spring Boot 2.0.3 和 Tomcat 8.5 中遇到了这个问题。我的解决方案是从我的 web.xml 文件中删除 &lt;absolute-ordering&gt; 元素。

【讨论】:

  • 你是如何做到这一点的,因为 Spring Boot 应用程序在 repo 中没有 web.xml 并且会生成一个放入 WAR 中?
  • @Scott Spring Boot 应用程序可以作为 WAR 文件部署在 servlet 容器中:请参阅 Traditional Deployment。在这种情况下,web.xml 文件位于 src/main/webapp/WEB-INF
【解决方案2】:

另一个原因可能是 Tomcat 版本。
Spring Boot 不适用于 Tomcat 10 #22414

【讨论】:

    【解决方案3】:

    可能问题出在Java版本和环境变量上……

    检查 JRE_HOME,在我设置为 1.8 后它开始工作

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-09-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-24
      • 1970-01-01
      • 2017-05-17
      • 2015-02-17
      相关资源
      最近更新 更多