Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jetty-users] Using Jetty to launch a Spring Boot application


On 9 Jan 2018, at 15:30, Robert Stroud <rjs@xxxxxxxxxxx> wrote:

On 9 Jan 2018, at 15:19, Jan Bartel <janb@xxxxxxxxxxx> wrote:

If you're using spring web libraries, then you will need to ensure that you have annotation processing turned on. See this chapter of the jetty docs: https://www.eclipse.org/jetty/documentation/9.4.8.v20171121/annotations.html

Aha - thank you. That will certainly be part of my problem…

I’ll let you know how I get on.

Jan, Joakim,

Thank you so much for your help and your quick response - turning on annotation processing fixed the problem. 

For the benefit of anyone with a similar problem in the future, I simply needed to add two lines to my launch method, namely:
// Enable annotation processing so that Spring Boot does its magic
Configuration.ClassList classlist = Configuration.ClassList
.setServerDefault(server);
classlist.addBefore(
"org.eclipse.jetty.webapp.JettyWebXmlConfiguration",
"org.eclipse.jetty.annotations.AnnotationConfiguration");

The example given in the Annotations chapter is more complicated because it configures JNDI as well, but for Spring Boot, you only need AnnotationConfiguration.

Best wishes,

Robert



Best wishes,

Robert


Jan

On 9 January 2018 at 15:23, Robert Stroud <rjs@xxxxxxxxxxx> wrote:
Hello,

I have inherited a legacy web application that we distribute as a WAR file with a separate launcher application that uses Jetty to launch the application. The web application is built using Grails, which uses the Spring framework.

The latest version of Grails uses Spring Boot to build the war file - my understanding is that Spring Boot depends on version 3.0 of the Servlet specification and uses a WebApplicationInitializer to bootstrap the configuration. In particular, there is no web.xml configuration in the war file.

I have updated our launcher application to use Jetty 9.4.8, which I believe supports Servlet 3.x, but when I launch the web application, I see what is effectively a directory listing of the war file that looks like this:

Directory: /

META-INF/ 102 bytes Jan 9, 2018 1:35:44 PM
WEB-INF/ 136 bytes Jan 9, 2018 1:35:42 PM
assets/ 8024 bytes Jan 9, 2018 1:35:44 PM

How do I configure Jetty to recognise the WebApplicationInitializer and load the Spring Boot application correctly? The current version of the launch code creates a WebAppContext in the usual way, but I assume I need to do something different.
WebAppContext context = new WebAppContext();
context.setWar(APPLICATION_WAR);
context.setContextPath("/");

server.setHandler(context);
server.addLifeCycleListener(this);
try {
server.start();
} catch (Exception e) {
serverError(e.getMessage());
}
Thank you

Robert





_______________________________________________
jetty-users mailing list
jetty-users@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/jetty-users



--
Jan Bartel <janb@xxxxxxxxxxx>
www.webtide.com
Expert assistance from the creators of Jetty and CometD

_______________________________________________
jetty-users mailing list
jetty-users@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/jetty-users



Back to the top