5

I'm thinking about developing a new web application using "light" components and not a full stack framework.

This article is my main inspiration!

Jetty : The web server. I'll probably use an embedabble version for development but with an option to export the application as a .war and use an external Jetty server for the production environment.

Guice/Guice-Servlet : For Dependency injection and for the servlet mapping + filters.

Jersey : For the routing + request/response json (de)serialization when required.

An important note : I'm aware some people will use this kind of stack with Jersey as a web services layer only, and will use a Javascript framework (Backbone, AngularJS, etc.) to consume those services and do most of the presentation logic in Javascript. I'm not ready yet for this kind of client stuff. I still prefere to use JSPs and been able to send plain HTML to clients that have javascript disabled.

So, my questions :

  • What is the best way to manage forms using Jersey? With Spring MVC (that I used on other projects) there is this concept of "backing objects" where the submitted POST data is automatically binded to a backing object that is then easy to play with. Is there something similar with Jersey?

  • I like all my routes to be defined in one specific routes file, not everywhere as @Path annotations which are, in my opinion, harder to manage. I'm pretty sure Jersey requires the use of those hardcoded JAX-RS's @Path annotations and doesn't allow an external routes configuration system, is that correct? Do you see any way I could centralize all routes with Jersey then?

  • I like the concept of reverse routing (like Play framework provides, for instance). And, again, I don't think Jersey can provide that functionality, is that correct?

  • Considering my previous questions, maybe Jersey is not the right technology to use? Do you know of others libraries I could use for the routing part in my stack?

  • Any other suggestions/tips for this kind of light Java web stack?

UPDATE :

I'm currently looking at UrlRewriteFilter for the routing part.

I'm also looking at the ActiveWeb framework, which is a "full stack" framework, but seems light and also seems to provide some functionalities I'm looking for : centralized routing config and reverse-routing.

4

1 回答 1

0

解释一些术语。Guice 和 Spring 解决相同的问题域,即依赖注入。因此,同时使用 Guice 和 SpringMVC 在某种程度上是不可能的,或者至少是相反的。

为了区分 Guice 和 Spring,说得好:

陡!更接近血腥的不可能。我认为 Guice 就像带一个女孩回家过夜。春天是一定的婚姻,一不小心,离婚就痛苦。– 蜘蛛 2011 年 10 月 7 日 16:25

Guice 确实是非常轻量级的 DI 框架。但是不支持路由和模板。您必须自己通过绑定 servlet 并自己使用模板引擎来完成。或者您可以使用Sitebricks。您可以将所有路由放入 SitebrickModule 配置方法中,如下所示:

public class MyAppConfig extends SitebricksModule {
@Override
protected void configureSitebricks() {
    at("/movies").show(MoviesPage.class); // basic page
    at("/actors").serve(ActorsPage.class); // service
    embed(SoundtrackPage.class).as("Soundtrack"); // brick
}

}

Sitebricks 还支持几个诱人的系统:MVEL、Freemarker、...

此外,您可以轻松地构建 REST 服务以供 javascript 使用:

Reply<Product> view() {
  return Reply.with(new Product("Anti-ageing cure"))
              .as(Json.class);
}

试试看。

于 2013-07-25T13:11:42.540 回答