Can anyone recommend a Java web framework that is

2019-01-25 20:17发布

问题:

We are looking to host a Java Domain Model (written using DDD) inside a web application. Ideally I would like to support RESTful resources and requests, having a single site to support both users and a REST api.

Ideally the same url could be used for both end users and the RESTful API of a given feature (with HTTP content types / negotiation specifying the difference).

I have done similar apps in Ruby on Rails and Asp.mvc, but have no experience doing anything like this in Java. Anybody have an experience or advice on where to start ? (Googling suggests that Spring v3 might be an answer, anybody have any thoughts on Spring 3 ?)

回答1:

For web services, Jersey is nice and easy. Spring 3 sounds like it will be good, but it's not out yet, and Jersey is full featured and supports SOAP and JSON out of the box. It's all annotation based aside from adding the servlet to your web.xml file which makes it probably easier to configure than even Spring plug-ins, but to avoid getting yelled at, I'll say maybe not.

For (MVC) web pages (user UI), I use Spring MVC or Struts.



回答2:

Spring 3 is not quite ready yet, but the current milestone build (M3) is stable enough to use for real. We're using its REST support in a production application already. It's pretty goodm, and integrates very nicely with Spring MVC. It's not JAX-RS compliant, but I don't see that as a problem.



回答3:

Restlets Framework http://www.restlet.org/

I've used this framework extensively, easy to use, really flexible and supports loads of features and more you'd expect from file upload to gzipping responses.

This module has Spring support too, really easy. For example:

web.xml

    <servlet>
        <servlet-name>webapi</servlet-name>
        <servlet-class>
            com.noelios.restlet.ext.spring.RestletFrameworkServlet
        </servlet-class>
    </servlet>

spring context

    <bean id="root" class="org.restlet.ext.spring.SpringRouter">
        <property name="attachments">
            <map>    
                 <entry key="/{variable}/your/restful/call/{variable2}">
                    <bean class="org.restlet.ext.spring.SpringFinder">
                        <lookup-method name="createResource" bean="yourBean" />
                    </bean>
                </entry>
            </map>
    </bean>

Framework also has a great documentation, first steps for newbies and a great WIKI.

This framework is very mature and actively improved, checkout the up and coming features.

It's also very easy to unit test your Restlet Resource endpoints using jmock.

Hope that helps.



回答4:

Spring is great. I've used it for some projects and recently also together with Liferay portal server for developing a portlet.

Why is Spring good?

  • It is a non-invasive framework: This means your application code doesn't depend on the framework (uses the IoC - Inversion of Control - concept). Spring does just what a good framework should do: support the development and not create further dependencies.
  • Dependency Injection: Spring uses the dependency injection concept which is great for avoiding dependencies on your code. You will define the dependencies in a spring xml configuration file where you define your beans and connections/relations among beans. This greatly facilitates reuse, lowers strong coupling among your objects which leads to better maintainability of your code.
  • It's not just a web framework: Spring MVC provides a lot of different controllers which are suitable in different contexts. But it isn't just a web framework but it supports the development on all the different layers (presentation, service and data access layers). For instance on the data access layers it nicely integrates with ORM mappers like Hibernate and it uses Aspect-oriented approaches for providing transaction management.
  • Lower-coupling -> increases testability: By avoiding strong coupling, the testability of your code will be increased. You can nicely inject mock objects for testing the different layers.

All in all, I just had positive experiences, because Spring really promotes best practices.



回答5:

I m a monorail MVC user ( castleproject.org), so i guess we come from a similar background. A few months ago we started working on the java stack in a different project, particularly with Spring.

Feature wise it s got 90% of what I m used to in monorail, however It is much more flexible, the downside to that is that there is a lot of configuration to get used to. Documentation is extensive sometimes too much so you dont know where to find something. Hope it helps