简体   繁体   English

任何人都可以推荐基于MVC的Java Web框架并支持REST吗?

[英]Can anyone recommend a Java web framework that is based on MVC and supports REST?

We are looking to host a Java Domain Model (written using DDD) inside a web application. 我们希望在Web应用程序中托管Java域模型(使用DDD编写)。 Ideally I would like to support RESTful resources and requests, having a single site to support both users and a REST api. 理想情况下,我想支持RESTful资源和请求,只有一个站点支持用户和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). 理想情况下,相同的URL可以用于最终用户和给定功能的RESTful API(HTTP内容类型/协商指定差异)。

I have done similar apps in Ruby on Rails and Asp.mvc, but have no experience doing anything like this in Java. 我在Ruby on Rails和Asp.mvc中做过类似的应用程序,但没有经验在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 ?) (谷歌搜索表明Spring v3可能是一个答案,任何人都对Spring 3有任何想法?)

Restlets Framework http://www.restlet.org/ Restlets框架 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. 我已经广泛使用了这个框架,易于使用,非常灵活,并且支持大量功能,并且您希望从文件上传到gzipping响应更多。

This module has Spring support too, really easy. 这个模块也有Spring支持,非常简单。 For example: 例如:

web.xml 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 . 框架还有一个很好的文档新手的第一步和伟大的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. 使用jmock对您的Restlet资源端点进行单元测试也非常容易。

Hope that helps. 希望有所帮助。

Spring 3 is not quite ready yet, but the current milestone build (M3) is stable enough to use for real. Spring 3尚未准备就绪,但目前的里程碑版本(M3)足够稳定,可用于真实版本。 We're using its REST support in a production application already. 我们已经在生产应用程序中使用其REST支持。 It's pretty goodm, and integrates very nicely with Spring MVC. 它非常好,并且与Spring MVC很好地集成。 It's not JAX-RS compliant, but I don't see that as a problem. 它不符合JAX-RS,但我不认为这是一个问题。

For web services, Jersey is nice and easy. 对于Web服务, Jersey非常简单。 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. Spring 3听起来很不错,但它还没有出来,而且Jersey功能齐全,支持开箱即用的SOAP和JSON。 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. 除了将servlet添加到你的web.xml文件之外,它都是基于注释的,这使得它甚至比Spring插件更容易配置,但是为了避免被大吼大叫,我会说也许不是。

For (MVC) web pages (user UI), I use Spring MVC or Struts. 对于(MVC)网页(用户UI),我使用Spring MVC或Struts。

Spring is great. 春天很棒。 I've used it for some projects and recently also together with Liferay portal server for developing a portlet . 我已将它用于某些项目,最近还与Liferay门户服务器一起用于开发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). 它是一个非侵入式框架:这意味着您的应用程序代码不依赖于框架(使用IoC - 控制反转 - 概念)。 Spring does just what a good framework should do: support the development and not create further dependencies. Spring确实是一个好的框架应该做的事情:支持开发而不是创建进一步的依赖。
  • Dependency Injection: Spring uses the dependency injection concept which is great for avoiding dependencies on your code. 依赖注入:Spring使用依赖注入概念,这对于避免依赖于代码非常有用。 You will define the dependencies in a spring xml configuration file where you define your beans and connections/relations among beans. 您将在spring xml配置文件中定义依赖项,您可以在其中定义bean和bean之间的连接/关系。 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. 它不仅仅是一个Web框架:Spring MVC提供了许多适用于不同环境的不同控制器。 But it isn't just a web framework but it supports the development on all the different layers (presentation, service and data access layers). 但它不仅仅是一个Web框架,而且它支持所有不同层(表示,服务和数据访问层)的开发。 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. 例如,在数据访问层,它很好地与像Hibernate这样的ORM映射器集成,并且它使用面向方面的方法来提供事务管理。
  • 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. 总而言之,我只是积极的经历,因为Spring真的推广了最佳实践。

I ma monorail MVC user ( castleproject.org), so i guess we come from a similar background. 我是monorail MVC用户(castleproject.org),所以我猜我们来自类似的背景。 A few months ago we started working on the java stack in a different project, particularly with Spring. 几个月前,我们开始在不同的项目中处理java堆栈,尤其是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. 功能方面它拥有我以前在单轨中使用的90%,但它更加灵活,其缺点是有很多配置需要习惯。 Documentation is extensive sometimes too much so you dont know where to find something. 文档有时太多,所以你不知道在哪里找到东西。 Hope it helps 希望能帮助到你

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 任何人都可以为Java推荐一个高效的UDP消息框架吗? - Can anyone recommend an efficient UDP messaging framework for Java? 谁能推荐一个可编写脚本的 Java 分析器? - Can anyone recommend a scriptable Java profiler? 任何人都可以推荐现有的Java文件存储库 - Can anyone recommend an existing java file repository 任何人都可以推荐一个基于C或Java的开源调度程序来嵌入另一个程序的核心吗? - Can anyone recommend an open source C- or Java-based scheduler for embedding as the heart of another program? 任何人都可以推荐现成的ACL Java lib吗? - Can anyone recommend an off the shelf ACL Java lib? 任何人都知道支持 HttpRanges 等的 Java 文件 servlet 框架 - Anyone know of a Java File servlet framework that supports HttpRanges etc 您可以为Java Web应用程序编码推荐一个标准,凉爽的环境吗? - Can you recommend a standard, cool environment for Java web application coding? Java MVC Web开发框架? - Java MVC Web development framework? 任何人都可以推荐执行所有典型协议(ssh等)的java FOSS服务器 - Can anyone recommend a java FOSS server that does all the typical protocols (ssh etc) Grails框架的产品可以归类为基于Java的Web应用程序吗? - Can the product of Grails framework be class as Java-based web application?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM