Tuesday, May 7, 2013

Embedding Jetty9 & Spring MVC

This post is re-done of one of my previous posts which was about embedding Jetty7. Now it's about new version - Jetty9 and also with support of Spring MVC. Just thought it would be a good idea to keep something like that as a reference. There is no much text below, this is because the source is clear enough and doesn't need much explanation. Though, feel free to raise questions in comments.

Lets start with Jetty server warpper. That's the main class which wraps all Jetty setup. Notice that there is no war here, there is no even 'web.xml'. It's all on plain folders and configured via code.

Here is class with main method. It's very simple, just starts the server and configures j.u.l's handler for slf4j (j.u.l is used by Jasper):

Here is Spring config, which was referenced by JettyServer class ('web-context.xml'). That config is used for all stuff related to String MVC.

Just an example controller:

And finally the list of dependencies in Gradle format:

References:
Embedding Jetty
Configuring Jetty JSP Support