OpenEJB 3.1 Supports EJB Singletons, Constructor Injection and Spring Integration
The latest release of OpenEJB, an open source lightweight EJB 3.0 implementation framework, supports EJB 3.1 Singletons, Constructor Injection and integration with Spring framework. Apache OpenEJB development team announced last week the release of OpenEJB 3.1 version. The latest version has support for some of the EJB 3.1 features that can be used not only as a standalone server, but as an embedded server in Tomcat, JUnit, Eclipse, Maven, Ant, or any other IDE or application. EJB 3.1 specification will be released as part of Java EE 6 (scheduled to be out early next year).
EJB 3.1 Singleton support adds new functionality to EJB such as application startup/shutdown hooks and multi-threaded capabilities. Much of what Stateless beans are used for now can be replaced by a multi-threaded Singleton. In addition to the embeddable EJB container and Collapsed EAR (ejbs in .war files) functionality, which will be part of EJB 3.1 release, this release contains support for the new EJB 3.1 Singleton Session bean type.
The Singleton feature ensures that there is exactly one instance of Stateless Session bean in the application which can be invoked concurrently by multiple threads, like a servlet. It can do everything a traditional session bean can do such as support local and remote business interfaces, web services, and concerns like security and transactions. Additionally, custom initialization and resource cleanup logic in the Singleton can be managed using its @PostConstruct (called when the application starts up) and @PreDestroy (called when the application shuts down) methods. This allows it to serve as an application lifecycle listener which is something only Servlets could do before. It has an @Startup annotation which is similar in concept to the servlet
The constructor injection feature allows Java EE resources like servlet, filter, listener or a JSF managed bean to be injected using the annotations at the constructor level. This way, the developers can still use final fields and plan old java constructors and avoid the setters and private field injection for managing the dependencies on the Java EE components.
Spring Integration feature allows the developers to embed Spring beans into OpenEJB or OpenEJB components into Spring applications. This can be done by injecting Spring beans into EJBs using @Resource annotation and EJBs can be injected into Spring via the standard Spring dependency injection (DI) mechanisms. This feature in OpenEJB 3.1 release is still an experimental feature and is subject to change based on user feedback.
OpenEJB 3.1 release also includes several enhancements to the existing features. Some of these enhancements are:
- Multicast Client-Server Discovery and grouping
- Injection Support for JSF 1.2 ManagedBeans
- EAR-style aggregation of modules discovered in the classpath
- ConnectorModule and PersistenceModule discoverable via the classpath
- Improved JavaAgent/JPA enhancement for Unit Tests
- EJBd protocol over SSL
- JDBC/DataSource based login module
Brandon Holt, Preston Briggs, Luis Ceze, Mark Oskin May 21, 2015