Spring框架中的EJB替代方案是什么 [英] What is EJB alternative in Spring Framework

查看:155
本文介绍了Spring框架中的EJB替代方案是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在尝试使用EJB创建应用程序之前,我正在尝试学习Spring Framework

I am trying to learn Spring Framework, before that I used to create application with EJBs

[Web services]->[Business Layer]->[DAO Layer] | [数据库]

以以下方式

  1. Web服务:使用Jerseyurl mappings的Restful API,同时支持JSON和XML格式(news/list.jsonnews/list.xml).端点(URL映射方法)接收到请求后,将通过查找(远程,本地)将其转发到相关的EJB. EJB处理所有事情,应用业务规则并以DTO(数据传输对象)的形式返回结果,然后Service将结果转换为所需的格式(JSON,XML)

  1. WebServices: Restful API using Jersey with url mappings, that support both JSON and XML format( news/list.json, news/list.xml). Once a request is received by an endpoint(url-mapped-method) it is forwarded to a relevant EJB through lookup(remote, local). EJB process every thing, apply business rules and return result as DTO(Data transfer object),Service then transform the result into required format (JSON, XML)

业务层:在EJB中使用remotelocal接口实现的业务层(门面),这些EJB可以调用其他EJB. WebService层(和/或Timer服务和MDB)也可以调用任何EJB.对于与计时器服务相关的功能,我使用EJB Timer Service,对于消息使用Message Drive Bean和拦截器进行日志记录和审核.

Business Layer: Business Layer (Facade) implemented in EJB with remote and local interfaces, these EJBs can call other EJBs. WebService layer(and/or Timer service and MDBs) can also call any of the EJBs). For timer service related functionality I used EJB Timer Service and for Messages used Message Drive Bean and interceptor for logging and auditing.

DAO层:使用EntityManager编写的所有与数据库相关的功能(添加,编辑,删除,搜索)JPA/Hibernate(实体bean和HQL)都在此处编写. 无缝事务支持,每个EJB的方法(基于查找)的调用都被视为一个单独的事务,而DAO层的调用方法是同一事务的一部分(前提是不提供任何额外的配置).在一个事务中执行多个操作如果一个数据库操作失败,则所有其他操作将自动回滚.每个表都映射为具有关系等的实体类.

DAO Layer: All the Database related functions(add,edit, delete, search) JPA/Hibernate using EntityManager are written here (Entity beans and HQL). Seamless Transaction support, each EJB's method (lookup-based) call is treated as a separate transaction and calling methods of DAO layer are part of same transaction(provided that no extra configuration is provided). multiple operations are carried out in a single transaction If one db operation fails all others are roll backed automatically. Each Table is mapped as an entity class with relations etc.

我已经在Spring MVC上工作,但是无法正确映射/理解以上架构 我对AOP有点儿了解,我认为它是Interceptor的完美替代品(或者至少对我有用)

I have worked on Spring MVC but could not map/understand correctly for above architecture I know bit about AOP and that I think is a perfect replacement for Interceptors (or at least it work for me)

现在我的问题是如何在Spring框架中替换所有这些?

  1. 春季的泽西(RestAPi)替代品>
  2. Spring中的EJB替代方案(由于EJB支持远程处理,因此对方法的每次查找调用都被视为事务,对EJB方法的调用可以被拦截,并且具有全状态和无状态形式)?
  3. 春季的计时器服务替代方案?
  4. Spring中的Message Drive Bean替代品?
  5. 拦截器替代方案是在春季进行AOP(根据我的经验,这符合我的目的)
  6. 春季使用JPA(实体管理器)的替代方案?

推荐答案

春季的泽西(RestAPi)替代品?

Jersey (RestAPi) alternative in Spring?

Spring MVC 做得很好,在我看来.只需在您的控制器中将您的方法注释为您要使用的REST API.

Spring MVC does this perfectly fine, in my opinion. Just annotate your methods in your controller as the REST apis you want to use.

Spring中的EJB替代方案(由于EJB支持远程处理,因此对方法的每次查找调用都被视为事务,对EJB方法的调用可以被拦截,并且具有全状态和无状态形式)?

EJB alternative in Spring (as EJB supports remoting, each lookup call to a method is treated as a transaction, calls to EJB's method could be intercepted and it comes with state-full and stateless flavors)?

没有完整的选择.有几种技术可以部分实现此功能:用于远程调用的Spring远程处理,作为事务的Spring事务,用于拦截调用的Spring AOP拦截器.但是,例如,在Spring上您不会得到远程调用上的XA事务.但是,Spring可以很好地与EJB配合使用,因此,如果您喜欢它们,仍然可以使用它们,并在软件的其他部分使用Spring.

There is no full alternative. There are several techniques that implement this in parts: Spring remoting for remote calls, Spring transactions as transactions, Spring AOP interceptors for intercepting calls. However, for example XA transactions on remote calls are something you don't get as such in Spring. Spring however works fine with EJBs, so if you prefer them, you can still have them and use Spring in other parts of your software.

Spring中的计时器服务替代方案?

Timer Service alternative in Spring?

Spring任务调度

消息驱动器Bean在Spring中的替代方案?

Message Drive Bean alternative in Spring?

消息监听器容器

拦截器替代品是Spring中的AOP(根据我的经验,这符合我的目的)

Interceptor alternative is AOP in Spring (As per my experience and that serve my purpose)

春季有几层拦截器.在mvc中有处理程序拦截器,有像SpringAutowiringInterceptor这样的bean调用拦截器,还有一些可以在多层中使用的基于AOP的拦截器.

There are several levels of interceptors in spring. There are handler interceptors in mvc, there are bean call interceptors like the SpringAutowiringInterceptor, and there are AOP-based interceptors that can be used in multiple layers.

JPA(实体管理器)春季替代方案?

JPA(entity manager) alternative in spring?

Spring也有多个.实际上,仅将JPA与 Spring-Data 一起使用,即 Spring JDBC 和其他数据如果Spring Data不是您想要的,则可以选择其他图层.

Spring has multiple of these as well. It's actually quite straightforward to just use JPA with Spring-Data, it's designed to integrate to JPA. There are Spring JDBC and other data layer alternatives though if Spring Data is not what you want.

这篇关于Spring框架中的EJB替代方案是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆