1
votes

I am trying to deploy a Spring boot web application on Jetty. I do not wish to use embedded jetty/tomcat for this. My main class is :

@SpringBootApplication
public class TransformerFacadeApplication extends SpringBootServletInitializer {

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

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

My REST resource has a controller defined as

@RestController
public class TransformController {

    private static final Logger LOG = LoggerFactory.getLogger(TransformController.class);


    @RequestMapping(value="/transform", method = RequestMethod.GET, produces = {MediaType.APPLICATION_JSON_VALUE})
    @ResponseBody
    public TransformStatus transform() {
    return new TransformStatus("foo");
    }
}

Please note the "/transform" path. Here are the deploy steps I then perform: 1. In my gradle build i have a 'war' plugin defined as:

apply plugin: 'war'

and the war name and version

war{
baseName = 'Foo'
version =  '0.0.1-SNAPSHOT'
}

2. This produces a .war file which I then want to deploy into jetty. I am using jetty-runner. With jetty-runner I try the following:

a) Defining a jetty context file foo.xml as:

<Configure class="org.eclipse.jetty.webapp.WebAppContext">
    <Set name="contextPath">/</Set>
    <Set name="war">/tmp/zzz/foo.war</Set>
</Configure>

Please note that I have subclassed SpringBootServletInitializer and overridden configure( as per Andy Wilkinson's suggestion). Finally,I do:

java -DDEBUG -jar jetty-runner-9.1.0.M0.jar foo.xml

This launch of jetty-runner results in the following log: Log snippet 1:

016-01-20 16:58:07.714:INFO:oejr.Runner:main: Runner
2016-01-20 16:58:07.803:INFO:oejs.Server:main: jetty-9.1.0.M0
2016-01-20 16:58:08.564:INFO:oejsh.ContextHandler:main: Started o.e.j.w.WebAppContext@79f7fcd0{/,file:/private/var/folders/vt/16kh5l5j6zqcmqy7p7dvrrs4wm0dvx/T/jetty-0.0.0.0-8080-foo.war-_-any-/webapp/,AVAILABLE}{/tmp/zzz/foo.war}
2016-01-20 16:58:08.564:WARN:oejsh.RequestLogHandler:main: !RequestLog
2016-01-20 16:58:08.577:INFO:oejs.ServerConnector:main: Started ServerConnector@36217796{HTTP/1.1}{0.0.0.0:8080}

When I hit it with a curl , curl -i -v http://localhost:8080/transform , I still get a 404.

Successful log snippet 2: ( when running as : java -DDEBUG -jar jetty-runner-9.1.0.M0.jar /tmp/zzz/foo.war )

System Property [DEBUG] has been deprecated! (Use org.eclipse.jetty.LEVEL=DEBUG instead)
2016-01-20 13:44:36.743:INFO:oejr.Runner:main: Runner
ShutdownMonitor not in use (port < 0): -1
2016-01-20 13:44:36.844:INFO:oejs.Server:main: jetty-9.1.0.M0
2016-01-20 13:44:39.564:INFO:/:main: Spring WebApplicationInitializers detected on classpath: [org.springframework.boot.autoconfigure.jersey.JerseyAutoConfiguration@3b783201, org.glassfish.jersey.server.spring.SpringWebApplicationInitializer@501afe27, com.myvest.microservice.TransformerFacadeApplication@1c23db87]

If you look at the 2 log snippets, the 2nd one is from a run without using a context. And this successful log snippet finds the Spring WebApplicationInitializer successfully. When using context foo.xml I think the Spring WebApplicationInitialzer is not being detected. Why would this be the case ?

1
What does your main class look like? Have you subclassed SpringBootServletInitializer and overridden configure? - Andy Wilkinson
@AndyWilkinson - I've updated my original post with the main class and more controller code. - Prakash Shankor
@AndyWilkinson - I've now subclassed SpringBootServletInitializer and overridden configure too. It resolves the exception in the run of the context.xml. But still doesn't resolve the 404. Thanks! - Prakash Shankor
That's strange. Can you share some code that reproduces the problem? - Andy Wilkinson
@AndyWilkinson - Sorry for the delay in responding to this. All the relevant code is in the post. I have added 2 log snippets too. The 1st snippet is the run with a context xml. The 2nd snippet is a direct run of the .war which is succcesful. - Prakash Shankor

1 Answers

0
votes

you should change the embed web server dependency to provided:

dependencies {
    // …
    providedRuntime 'org.springframework.boot:spring-boot-starter-jetty'
    // …
}