简体   繁体   中英

using spring with ejb

have you used spring and EJB together in a project? It it's good or not. And how, what you used spring and EJB for? thanks

The Spring manual has a comprehensive chapter on EJB integration:

[...] 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. Additionally, using Spring to access services provided by EJBs allows the implementation of those services to later transparently be switched between local EJB, remote EJB, or POJO (plain old Java object) variants, without the client code having to be changed.

The value lies mainly in accessing stateless session beans, since they conform more closely to Spring's service-oriented model of doing things. You also get some value from stateful session beans and entity beans, but only to a limited degree. EJB2 entity beans are so badly designed that no amount of Spring polishing can hide the nastiness beneath.

The question remains as to why you would want to do this. Spring's own capabilities are at least a match for EJB. The most common reason for mixing the two is if you have an existing codebase that uses EJB, and you need to integrate a Spring application with it. If there's no existing EJB, there isn't really any point, you may as well stick with Spring all the way through.

Just to add a little more detail on the approach - we will have a simple Spring POJO that will have an EJB injected into it using the @EJB annotation. This POJO will be loaded using a spring context file that will be part of the server deployment. When the server comes up, Spring will automatically inject the EJB resource into the POJO as it has Pitchfork integrated into Weblogic. To test this code, once the app is deployed, we can have an intermediary EJB which will have our implementation of BeanFactoryBean (an EJB as well) injected into it, that will lookup the POJO using BeanFactory. We will then invoke a method on the POJO that will use the injected EJB to call a method on that EJB and return the value. More details on the example could be found at this location

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM