7
votes

For a pet project I would like to have an embedded Jetty run a Spring Web MVC app. I've used Spring in web containers (where it's easy to tell "where to start") and I've used embedded Jetty without Spring.

It feels a bit like the chicken or the egg problem if I want both to work together. What is the best way to organize the project? In other words, what shall I put in main()? Should it be a Spring app that happens to have Jetty as a bean (what about contexts then?)? Or should I start Jetty alone and plug Spring in via servlet listener? What are the caveats?

3

3 Answers

3
votes

Jetty in a Spring container is used to start webapp, springified or not. The webapp and your webapp don't have the same Spring context without tricks.

So, you have to create a Jetty server in your main, add your webapp and start the server. The best way is using a web.xml like a common Java EE server, and add this descriptor to your Jetty server.

0
votes

I think it is more reasonable to start Jetty alone and plug Spring in via servlet listener in web.xml. Let Spring manager all the app specific beans and let jetty focus on running your app, and maybe some day you can deploy you app to antoher servlet container without changing anything.