开发者

Embedded Jetty and Spring Web MVC

For a pet project I would like to have an emb开发者_运维问答edded 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?


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.


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.


This is one way to embed Jetty in Spring http://www.springbyexample.org/examples/embedded-spring-web-services.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜