Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Difference between EJB and Spring

  • Last Updated : 24 Dec, 2020

EJB and Spring both are used to develop enterprise applications. But there are few differences exists between them. So, in this article we have tried to cover all these differences.

1. Enterprise Java Beans (EJB) :
EJB stand for Enterprise Java Beans. It is a server side software component that summarizes business logic of an application. An EJB container provides the run time environment for web related software elements including computer reliability, Java Servlet Lifecycle (JSL) management, transaction procedure and other web services. To run an EJB application, we need an application server such as Jboss, Glassfish, Weblogic, Websphere etc. It performs Life Cycle Management, Object Pooling, Transaction Processing, Security, etc. There are three types of EJB.

Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.

  • Session Bean –
    Session bean contains business logic that can be invoked by local, remote or webservice client. There are two types of session beans :
    (i). Stateful session bean and (ii). Stateless session bean.
  • Message Driven Bean –
    Like Session Bean, it contains the business logic but it is invoked by passing message.

  • Entity Bean –
    It summarizes the state that can be persisted in the database. It is deprecated. Now, it is replaced with JPA (Java Persistent API). There are two types of entity bean :
    (i). Bean Managed Persistence and (ii). Container Managed Persistence.

2. Spring :
Spring is an open source lightweight framework that allows Java EE 7 developers to build simple, reliable, and scalable enterprise applications. This framework uses various techniques such as Aspect-Oriented Programming (AOP), Plain Old Java Object (POJO), and dependency injection (DI), to develop enterprise applications. This framework helps you to manages the business object. It made the development of Web applications much easier than compared to classic Java frameworks and Application Programming Interfaces (APIs), such as Java database connectivity (JDBC), JavaServer Pages (JSP), and Java Servlet. The features of the Spring framework such as Inversion of control (IoC), Aspect-Oriented Programming (AOP), and transaction management, make it unique among the list of frameworks.

Difference between EJB and Spring :

SpecificationEJB is a specification of Java EE.Spring is a framework.
Dependency InjectionIt can inject anything in the container including EJB Data sources, JMS Resources, and JPA Resources.It can inject anything including list, properties, map, and JNDI resources.
Transaction ManagementIt supports only JTA transaction Manager.It supports multiple transaction manager such as JTA, JDBC, and Hibernate.
PersistenceIt tightly integrated to JPA.It supports various persistence technologies such as JDBC, Hibernate, JPA, and iBatis.
MessagingIt provides out of the box messaging capabilities through Message Driven Beans.We need to add listener configuration for each message.
SchedulingIt provides simple scheduling through EJB Time Service.We need to add and configure Quartz for scheduling.
SecurityIt supports both declarative and programmatic security through JAAS.It provides declarative security through the Spring configuration file.
AOPIt provides limited support through interceptors.It provides robust support through AspectJ.

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!