Openejb :: container:: The function and characteristics of the feature provided by the framework
OpenEjb is an open source container for Java applications. It provides many functions and features to simplify the development and deployment of the application.The following is an introduction to the key functions and characteristics provided by OpenEjb's core framework.
1. Seamless integration: OpenEjb can be seamlessly integrated with other technologies in the existing Java Ee container (such as Java Servlet, Javaserver Pages, and Java Persistence API).It can run as a part of the WAR (Web Archive) or Ear (Enterprise Archive) applications.
2. Lightweight container: Openejb is a lightweight container that can be embedded in the application, reducing dependence on external servers.It can perform unit testing as an embedded container, and can speed up deployment and restart during the development process.
3. Transparent dependencies injection: OpenEJB through dependency injection (DI) function makes the dependency statement between components simple and transparent.Components only need to use annotations or XML configurations to declare its dependent items that need it, and OpenEjb will automatically inject it.
For example, the following code example demonstrates how to use @ejb notes to inject EJB into a web service:
@WebServlet("/myServlet")
public class MyServlet extends HttpServlet {
@EJB
private MyEJB myEJB;
protected void doGet(HttpServletRequest request, HttpServletResponse response) {
myEJB.doSomething();
}
}
4. Affairs support: OpenEjb provides a powerful transaction management function, which can automatically handle the start, submission and rollback of the transaction, and support different transaction isolation levels.Developers can use annotations or XML configurations to define transaction attributes.
The following code example demonstrates how to use @transactionattribute comments to define transaction attributes in an EJB:
@Stateless
public class MyEJB {
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void doSomething() {
// Execute transaction operation
}
}
5. Security support: OpenEjb provides support for Java EE security models, which can easily configure and manage the security requirements of applications.By using annotations or XML configurations, resources and access permissions can be defined.
6. The persistence of container management: OpenEjb provides the durable support of container management through the Java Persistence API (JPA).It can automatically handle the creation, update and deletion of the physical class, and provide query and transaction support.
The following code example demonstrates how to use @persistenceContext annotations to inject an EntityManager into an EJB:
@Stateless
public class MyEJB {
@PersistenceContext
private EntityManager entityManager;
public void saveEntity(MyEntity entity) {
entityManager.persist(entity);
}
}
In summary, OpenEjb's core framework provides many functions and characteristics, making development and deployment of Java applications easier and efficient.Seamless integration, lightweight container, dependency injection, transaction support, security support, and durability of container management are the key features of OpenEjb.