Openejb :: Container :: Core framework Frequently Asked Questions Answers
Openejb :: Container :: Core framework Frequently Asked Questions Answers
1. What is Openejb Container Core framework?
OpenEjb Container Core framework is an open source container framework for the construction of scalable, high -performance enterprise Java applications.The framework provides a lightweight container for managing the life cycle of EJB (Enterprise Java Beans) components, dependency injection and transaction management.
2. How to integrate OpenEjb Container Core framework into the Java project?
You can use Maven to rely on management tools to add the following dependencies to the pom.xml file of the project:
<dependencies>
<dependency>
<groupId>org.apache.openejb</groupId>
<artifactId>openejb-core</artifactId>
<version>4.7.7</version>
</dependency>
</dependencies>
3. How to create a simple EJB component?
The following is an example. How to use the OpenEjb Container Core framework to create a simple stateless session bean:
import javax.ejb.*;
@Stateless
public class MyBean {
public String sayHello() {
return "Hello, World!";
}
}
4. How to configure the data source of the OpenEjb Container Core framework?
You can configure the data source for the Openejb container in the `Openejb.xml` file in the project.The following is an example configuration:
<resources>
<Resource id="myDataSource" type="DataSource">
JdbcDriver com.mysql.jdbc.Driver
JdbcUrl jdbc:mysql://localhost/mydatabase
UserName myuser
Password mypassword
</Resource>
</resources>
5. How to manage transaction management in the OpenEjb Container Core framework?
Openejb container provides management and control of transactions.You can use the transaction attributes of the method to define the method of defining the method, as shown in:
import javax.ejb.*;
@Stateless
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public class MyBean {
public void performTransaction() {
// ... Business logic ...
}
}
In the above example, the default transaction attribute is required, which means that the method will be executed in new transactions. If there is currently there is transaction, the transaction will be hung.
I hope that the above content can help you solve common problems related to the OpenEjb Container Core framework.