What is EJB?
1. Enterprice JavaBeans (EJB) is a standard server-side component model for distributed business applications. 2. Applications written with the EJB architecture are extensible, transactional, and user-safe. 3. Applications written in EJB can be deployed on servers such as JBoss, WebLogic, and so on (Tomcat is just a web container and does not contain an EJB container)4. EJB is used to write MVC's business layer (Model) code 5. EJB provides many services that need to be used in enterprise development, such as transaction management, security, persistence, and distribution. Because these services are provided by containers, we do not need to develop them ourselves. 6. The difference between EJB and spring, EJB is used to do distributed system. Spring is a better choice if the project does not require a distributed deployment
Deploy the public business to a single server. This allows different services to access the same business, enabling maximum reuse at the component level
introduce the commonly used annotations:
* javax.ejb.Stateless *indicates that this class is a stateless session bean*managing beans With instance pool technology* * @Stateless (name="ABC") *indicates that the Jndi name for this class is ABC*do not specify a simple name for this class by default* ****************************
* *javax.ejb.Stateful*indicates that this class is a stateful bean*save their information for each user*using the activation management bean*session information is persisted from memory to disk for passivation (serialization)*restore from disk to memory active (deserialization)*if it expires, it will automatically erase the information on the disk.* ***************************
* *Javax.ejb.Remote*indicates that it is a remote interface*do not write default is local interface (locally)
*********************************
* * javax.ejb.Local
* *Local Interface* *****************************
* * When EJBS and clients run concurrently within a JVM, the local interface is preferred
*
*Javax.ejb.EJB
* Automatic injection of other EJB properties, similar to spring's org.springframework.beans.factory.annotation.Autowired
**********************************
*@Resource(mappedname= "Java:jndi's name") DataSource da;
* Inject Other resources
*
*
1. Understanding EJBS