3
votes

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
4
Which url do you invoked localy, and which one on JBOSSEWS? - Ralph
Locally : localhost:8080/greeting. Online : jbossews-flco.rhcloud.com/greeting. - Florian Courtial
The ROOT.war is available on the / I suspect you renamed it from greeting.war to ROOT.war? - M. Deinum
No, I renamed app.war to ROOT.war, greeting is a parameter passed to the Spring MVC controller to the RequestMapping. - Florian Courtial

4 Answers

2
votes

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

0
votes

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

0
votes

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...

0
votes

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.