spring - 包含在 openshift tomcat 上手动部署的 spring boot 应用程序的 WAR 不起作用

标签 spring spring-mvc tomcat7 openshift spring-boot

我创建了一个 Spring Boot 应用程序,然后创建了一个 war。

在我的本地服务器上,应用程序可以正常运行。

我将此应用程序重命名为 ROOT.war,使用 git 将其放入 webapps 目录并重新启动服务器,从而将此应用程序添加到 JBOSSEWS 盒中。

但是我总是找不到404。

tomcat 日志是:

new-host-3:jbossews JARVIS$ rhc tail jbossews
Aug 30, 2014 3:27:25 AM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.54
Aug 30, 2014 3:27:25 AM org.apache.catalina.startup.HostConfig deployWAR
INFO: Deploying web application archive /var/lib/openshift/540178a84382ec94b8000b75/app-        root/runtime/dependencies/jbossews/webapps/ROOT.war
Aug 30, 2014 3:27:37 AM org.apache.catalina.startup.HostConfig deployWAR
INFO: Deployment of web application archive /var/lib/openshift/540178a84382ec94b8000b75/app-root/runtime/dependencies/jbossews/webapps/ROOT.war has finished in 11,864 ms
Aug 30, 2014 3:27:37 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-127.10.90.1-8080"]
Aug 30, 2014 3:27:37 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 12059 ms

最佳答案

确保您的主类 Application 扩展了 SpringBootServletInitializer

Initialize the servlet

By converting this into a WAR file with no XML files, you need a different signal to the servlet container on how to launch the application.

import org.springframework.boot.context.web.SpringBootServletInitializer;

public class HelloWebXml extends SpringBootServletInitializer {

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

}

HelloWebXml is a pure Java class that provides an alternative to creating a web.xml. It extends the SpringServletInitializer class. This extension offers many configurable options by overriding methods.

来源:Spring.io Guide

关于spring - 包含在 openshift tomcat 上手动部署的 spring boot 应用程序的 WAR 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25580218/

相关文章:

java - JUnit 测试(使用 Spring MVC 和 Hibernate): IllegalArgumentException: Unknown entity

java - 我想使用 spring 3 获取 Controller 中 pojo 中的表单数据集,就像 struts1.2 方法一样

mysql - 为 Google Cloud SQL 实例启用 "Allow only SSL connection"并从配置了 SSL 的 Spring 应用程序连接到它

eclipse - 在 Eclipse Luna 中获取 "Project facet Java version 1.8 is not supported."

java - 如何在特定时间发送电子邮件?

spring - EL 自动完成/代码协助 Eclipse 和 Spring Beans

java - Spring Web MVC : Simple controller - $-expression doesn't work

mysql - JDBC 和 Hibernate 查询性能缓慢(与 PhpMyAdmin 相比)

spring - 如何使以 .jsp 结尾的无效 url 使用 spring 404 页面?

java - Spring CrudRepository 会抛出什么 RuntimeException?