Florian Courtial
Florian Courtial

Reputation: 930

WAR containing spring boot application manually deployed on openshift tomcat does not work

I created a Spring Boot application, then I created a war.

On my local server the app works correctly.

I added this app to a JBOSSEWS cartridge by renaming it ROOT.war, putting it in the webapps directory using git and restarting the server.

But I always have a 404 not found.

The tomcat logs are :

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

Upvotes: 3

Views: 1902

Answers (4)

njjnex
njjnex

Reputation: 1555

There are reasons:

  1. Check you don't use Java 8 if so turn it to Java 7 or DIY. When you using Java 8 container will not deploy war (tested myself).
  2. Use SpringBootServletInitializer as @Jakub said.

Upvotes: 0

Jakub Złoczewski
Jakub Złoczewski

Reputation: 451

Make sure that your main class Application extends 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.

Source: Spring.io Guide

Upvotes: 2

Christoph Höller
Christoph Höller

Reputation: 11

I had the same problem and was able to solve it by copying the .openshift directory from the original git-repo into the repo folder of the tar.gz. So afterwards my directory structure looked something like this:

myApp.tar.gz - dependencies - - jbossews - - - - webapps - - - - - ROOT.war - repo - - .openshift - - - - markers - - - - - java7 ...

I think the problem in my case was, that tomcat tried to deploy the application with JDK 1.6, as this seems to be the fallback, when there is no java7 file in the markers directory...

Upvotes: 0

user2879327
user2879327

Reputation:

Make sure that you removed the pom.xml file and the src/ directory, so that it will deploy your ROOT.war file when you do a git push. You can check out this kb article for further information: https://help.openshift.com/hc/en-us/articles/202399740-How-to-deploy-pre-compiled-java-applications-WAR-and-EAR-files-onto-your-OpenShift-gear-using-the-java-cartridges

Upvotes: 0

Related Questions