Take you into EJB--EJB and Spring comparison,

Source: Internet
Author: User

Take you into the EJB--EJB and Spring comparison (turn ),

Http://blog.csdn.net/jnqqls/article/details/17723417

Through summing up and learning the EJB series, we have a basic understanding of EJB, but in order to further study EJB, it is necessary for us to compare the two with spring, which we are very familiar with. By comparing them, we can understand the similarities and differences between the two, which is more conducive to our in-depth understanding of the two.

 

We have all had this experience. When developing applications, it is more knowledgeable to choose which technology. during my recent interview, I also asked many questions about technical selection. A typical example is as follows: why does your system choose EJB3.0 instead of Spring or why does it not select EJB.

 

In general, which technology will we use to solve specific problems most effectively? This decision is not easily made. We need to understand their respective strengths and weaknesses. Next we will compare Spring and EJB.

 

One of the first concepts we need to understand is that Spring is a specific implementation, while EJB3.0 is a J2EE specification, which is a big conceptual difference. but in some specific places, they have many things in common. for example, they all provide the middleware service to the Java application. If you look at the history, it will be clearer. Spring was developed to oppose EJB. Of course, EJB2 did have many shortcomings at that time, but with the release of the new version of EJB, EJB3.0 overcomes some shortcomings of previous versions and draws on Spring-related content.

What functions does Spring and EJB provide? Starting from the most direct problem, we can intuitively see their respective characteristics. spring defines the J2EE application framework of the component layer. EJB is an object-oriented and distributed enterprise-level application development and deployment component architecture. one is the framework and the other is the architecture. the framework is more implemented, while the architecture is more defined.

Data Persistence

Spring and EJB3.0 provide excellent support for the key part of data persistence. Spring integrates many popular Persistence frameworks, including JDBC, hibernate, JDO, iBatis, and JPA. The emergence of EJB3.0 replaces the Entity bean with JPA. JPA is committed to providing a simple, lightweight OR ing framework. This specification defines two interfaces, one for interaction between persistence providers and the other for ing between entities and relational databases.

 

In EJB3, you can obtain JPA data access by using the entityManager object provided by @ PersistenceContext annotation. In Spring, you can obtain Hibernate data access by injecting SessionFactory objects. Many of us use JPA to operate data objects for EJB by default, while Spring uses Hibernate to operate data objects. But in fact, Spring also supports using JPA to operate data objects, and Spring can support JPA through @ PersistenceContext annotations.

 

 

About lightweight and heavyweight

 

The lightweight and heavyweight frameworks have different focuses on solving problems.

The Lightweight Framework represented by Spring focuses on reducing the development complexity and reducing the processing capability (suitable for developing small and medium-sized enterprise applications. On the one hand, the lightweight framework is developed based on POJOs as much as possible, so that the application does not depend on any container, which can improve the development and debugging efficiency. On the other hand, most of the lightweight frameworks are open-source projects, the open-source community provides good design and many quick building tools as well as a large number of open-source code available for reference, which is conducive to the rapid development of projects.

 

As a heavyweight framework, EJB emphasizes high scalability and is suitable for large-scale enterprise applications. In the EJB architecture, all issues related to infrastructure services and underlying allocation problems are handled by application containers or servers, the EJB container provides a dedicated system performance solution by reducing the number of database accesses and distributed processing to fully solve system performance problems.

 

The generation of lightweight frameworks is not a denial of heavyweight frameworks. To some extent, they can be said to be complementary. Lightweight frameworks are developing to develop enterprise applications with more powerful and complete functions; the new EJB specification EJB3.0 is trying to simplify the use of J2EE so that EJB is not only good at handling large enterprise systems, but also developing small and medium systems. This is also an effort to make EJB lightweight. It is also a good solution for large enterprise applications and small and medium-sized applications that may involve capacity expansion in the future.

Provider independence

 

One of the most important reasons for developers to choose the JAVA platform is its vendor independence. EJB3.0 is an open standard designed to have no dependency on providers. The EJB 3.0 specification is compiled and supported by mainstream open-source organizations and vendors in the Enterprise JAVA Community. The EJB3.0 framework allows developers to implement applications independently of application servers.

 

For example, JBoss's EJB3.0 implementation is based on Hibernate, and Oracle's EJB3.0 implementation is based on TopLink. However, when running applications on JBoss or Oracle, developers do not need to learn Hibernate, you do not need to learn the unique APIs provided by TopLink. Vendor independence distinguishes the EJB3.0 framework from any other POJO middleware framework.

 

Many people think that although the Spring framework can be used on any application server, Spring-based applications are still restricted by Spring itself, and various special services provided by Spring used in applications. But is it true? We should know that in Spring applications, JtaTransactionManager uses an automatic detection mechanism, whether it is MBeans application server or Tomcat application server. Similarly, when JPA is used, Spring automatically detects the persistence. xml file and creates an EntityManagerFactory object. In the above mechanisms, Spring, whether annotated or XML, can be the same as EJB applications and has nothing to do with the application server provider.

 

Reference: Make the Right demo-with Our Side-by-Side Comparison of Springand EJB 3.0

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.