简体   繁体   English

如何通过基于Java的Web服务在现有数据模型上轻松公开CRUD操作?

[英]How do I easily expose CRUD operations, via a Java based Web Service, on an existing data model?

I have an existing domain model annotated with JPA annotations that I would like to easily expose CRUD operations on via Web Services. 我有一个现有的域模型,上面标注了JPA批注,我想通过Web服务轻松地公开CRUD操作。 I already have DAOs to perform CRUD operations on all of my entities in my domain. 我已经有DAO在域中的所有实体上执行CRUD操作。

Does anyone know of an way to do this that does not involve a tremendous amount of effort? 有谁知道不需要花费大量精力的方法吗?

It depends on how my operations and services and what you call "a tremendous amount of effort." 这取决于我的运营和服务方式以及您所说的“巨大努力”。 You're likely to be disappointed if doing anything more than pushing a button and having your wishes come true is too much. 如果您只想按一下按钮并实现自己的愿望,那么您可能会感到失望。

But there are three parts to your problem: 但是,您的问题分为三个部分:

  1. Writing DAOs that expose the CRUD operations. 编写公开了CRUD操作的DAO。 I'd recommend an interface-based approach. 我建议基于接口的方法。
  2. Exposing these as "contract-first" web services, either SOAP or REST. 将它们公开为“合同优先”的Web服务,即SOAP或REST。
  3. Mapping HTTP requests and responses to your API. 将HTTP请求和响应映射到您的API。

I'd recommend Spring, because it'll help with DAOs, web services, and mapping. 我建议使用Spring,因为它将对DAO,Web服务和映射有所帮助。 But I don't know if it'll be as effortless as you want it to be. 但是我不知道它是否会像您想要的那样轻松。

You can use Apache CXF in combination with Spring ROO to achieve this. 您可以将Apache CXFSpring ROO结合使用以实现此目的。

Please see this post for more details: http://forum.springsource.org/showpost.php?p=284028&postcount=4 请参阅此帖子以获取更多详细信息: http : //forum.springsource.org/showpost.php?p=284028&postcount=4

Throw some annotations on that DAO, like @WebService and @WebMethod and use your JAX-WS implementation of choice. 在该DAO上添加一些注释,例如@WebService和@WebMethod,并使用您选择的JAX-WS实现。 You can use JAX-WS Commons Spring for Spring integration. 您可以将JAX-WS Commons Spring用于Spring集成。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM