Comparison of EJB3 and spring technology systems

Source: Internet
Author: User

With the EJB3 specification and the upcoming release of the Java EE Application Server that supports EJB3, the new War of Java EE Architecture will begin, and in the past 3 years spring has been the most prosperous of Java EE application development infrastructure, What should you choose to face EJB3 and spring?

As an architect, I love and hate the EJB, spring, hate and love, and now we have to do the two major technical system to do a comprehensive analysis and comparison, I hope to give you in the technical selection of a better reference.

1. The rule of law VS "democracy"

EJB specification has been JCP by international organizations, once adopted, that is, as an official standard, and the manufacturers will spare no effort to promote, so for enterprise applications, EJB is the law, EJB for enterprise application infrastructure for the time being called the rule of law; Spring comes from the open source community, A popular system standard, developed by a large number of open-source software developers, is designed with the IOC (reverse control) as its core, advocating the so-called "0" intrusive design principles, for the moment called democracy.

EJB-supporting application server is generally a all-inclusive product, including the construction of enterprise application needs, if the need for additional expansion is not easy, if not satisfied with an application server, then can and also can only replace the entire application server, fortunately, due to the application of the server market blossom, From free to low-end to high-end, you can choose from anywhere; Spring has evolved from the IOC container to provide a complete enterprise application framework by continually integrating AOP, MVC, or/mapping, and almost every service you can think of. For an application, you are free to choose the specific technical framework of the implementation, SSH is the most commonly used set of combinations, however, without saying whether each architect has the right choice, anyway, the final choice at the beginning of the design once determined, to replace it is not so easy, you can not easily put a based on Spring + The application of struts is easy to migrate to Spring + webwork, and it's not easy to migrate a spring + hibernate based application easily to spring + iBatis, so for applications that require long-term maintenance and development, You can only hope that the framework you are using will be well developed and can be upgraded to ensure forward compatibility.

To sum up, EJB because of the whole world is standard, it is like an international law, once followed, the global, you can easily in WebSphere, WebLogic and even the switch between JBoss, so if you choose EJB, you will be in a "legal" Environment, and spring is the most democratic of the world, however, once the whole structure has been determined, but become autocratic, as if the United States-style democracy, once conquered by it, it becomes its dictatorship rule, want to break free from its control can not so easy, and the stakes, we savor it.

2. Lightweight components vs lightweight cores vs lightweight containers

About the lightweight kernel, whether it is true or not, today's application servers are claiming to use micro-kernel technology, based on the establishment of Java EE Services built into a perfect application server, and spring itself is an IOC based lightweight kernel, and then through the integration of Third-party servers to provide a complete architecture.

The EJB component, once considered a heavyweight component, has been criticized for the important goal of EJB3 specification is to simplify EJB development and provide a lightweight component solution for container management.

But it is necessary to remind lightweight components do not mean that the container that provides the service is lightweight, whether it is EJB2 or EJB3, the application server is a heavyweight service because it needs to manage the lifecycle and behavior of the components, and provides a built-in service; at least for now, The existing application server offers not enough containers to be lightweight, and personally, I like the JBoss 2.4 version, which has the functionality I need and is simple enough, and now that the JBoss 4 startup speed has gradually let me lose patience with it.

For spring, too, the lightweight kernel does not mean that the entire framework is lightweight, nor does it mean that the entire application architecture based on spring is lightweight. For Spring, you need to find and glue a variety of services, and then allow them to work together stably, if the application of technology needs more, scalability requirements are high, you will continue to add other services in the application services, such as: resource pool, Message Queuing, clustering and so on. When these are joined, the spring solution is already as heavyweight as the Java EE Application Server solution.

The pursuit of simplicity, lightweight, is the goal of every application architecture, for enterprise application construction, lightweight component standard + lightweight core + lightweight container, and to build a lightweight application platform, is the ultimate need. If a lightweight container appears, it will help EJB3 to regain a favorable position in the enterprise application.

3. Manageability and controllability

This problem may not be a problem for a one-time deliverable, but for products with higher quality requirements and longer lifecycle, it is an important factor in measuring the platform and architecture.

Based on the application of the spring architecture, due to excessive freedom and flexibility, as the project progresses, the gradual integration of the Third-party framework is increasing, it is difficult to ensure that integrated services and written components have no loopholes, and even serious conflict between each other, then control the quality of the entire project is a difficult problem, Just a page after page of the configuration file, you know the future maintenance costs will increase, think back to the EJB2.0 era of Ejb-jar.xml bar; EJB because the integration is standard service, and the component model is also fixed, and the application server generally provides the console, Used to view the various properties of the runtime, and to manage the service in real time, which is obviously better than the application of spring development.

4. Functional Contrast 4.1 IOC container, AOP capabilities

The IOC's ability to spring is slightly stronger, but in EJB3 it can be injected entirely in a annotation way, much simpler in development, and better for some relatively fixed injections, with annotation, and for some injections that may require constant change, XML is more flexible, and EJB3 just provides two solutions. If you are already suffering from XML phobia, then EJB3 will undoubtedly give you relief.

At the same time, EJB3 components support a variety of ways to inject, such as depending on the name, interface, or Jndi name, and also support the use of @persistencecontext injection Entitymanager, @Resource inject server resources, such as Ejbcontext, Timerservice, and some annotation have become part of the JDK6 and may be directly supported by JDK in the future.

AOP, if you need thorough AOP and integrate ASPECTJ in spring, then EJB3 natural, but if your project is based on the principle of adequacy, only the general method of intercepting the aop,ejb3 provided in the sense of the various callback methods should be able to meet your needs.

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.