Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is EJB alternative in Spring Framework

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

[Web services]->[Business Layer]->[DAO Layer] | [Database]

in following way

  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)

  2. 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.

  3. 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.

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)

Now my question is how all these could be replaced in Spring framework?

  1. Jersey (RestAPi) alternative in Spring>
  2. 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)?
  3. Timer Service alternative in Spring?
  4. Message Drive Bean alternative in Spring?
  5. Interceptor alternative is AOP in Spring (As per my experience and that serve my purpose)
  6. JPA(entity manager) alternative in spring?
like image 895
PHP Avenger Avatar asked Oct 29 '15 13:10

PHP Avenger


People also ask

Which is better EJB or Spring?

If we want to develop such an application that has lots of configuration and that has control at the container level, we should go with Spring. If we do not want to spend too much time in configuration and the application has a pre-defined tech stack, we can use EJB.

Is EJB used in Spring?

However, it is important to note that using Spring does not prevent you from using EJBs. In fact, Spring makes it much easier to access EJBs and implement EJBs and functionality within them.

What are the different types of EJBs?

There are three types of EJBs: session beans, entity beans, and message-driven beans.

Is Java Bean and EJB are same?

A JavaBean is a Java class that encapsulates multiple objects and conforms to certain conventions. JavaBeans are used mainly for client-side development. An enterprise bean (EJB) is a Java class imbued with specific server-side capabilities. Enterprise beans are used in large-scale business applications and systems.


1 Answers

Jersey (RestAPi) alternative in Spring?

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

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)?

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.

Timer Service alternative in Spring?

Spring task scheduling

Message Drive Bean alternative in Spring?

Message Listener Containers

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

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(entity manager) alternative in spring?

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.

like image 124
eis Avatar answered Oct 04 '22 19:10

eis