Managed beans

The Managed Beans specification (JSR -316) is used to define managed beans for the Java™ Platform Enterprise Edition (EE) and is a part of the Java EE 6 platform.

Managed beans are container-managed objects with minimal supported services, such as resource injection, life cycle callbacks and interceptors, and have the following characteristics:
  • A managed bean does not have its own component-scoped java:comp namespace. Therefore, its resources can be defined in java:app and java:module only.
  • Managed bean methods run in the same thread as the calling thread. For example, the method does not start its own thread.
  • Managed bean methods use the same context as the calling thread.
  • Managed beans are defined with the javax.annotation.ManagedBean annotation.
  • A managed bean can have an optional name and is bound into java:module and java:app only if a name is present; for example:
    @ManagedBean(“myCart“)
    public class Cart { ... } 
  • A reference to a managed bean can be obtained through resource injection, or lookup in java:module or java:app, when a name is specified.
  • Managed beans support lifecycle callbacks with the javax.annotation.PostConstruct and javax.annotation.PreDestroy annotations.
You can specify the binding information that will map resources to JNDI names using an ibm-managed-bean-bnd.xml file. The following example shows the use of the ibm-managed-bean-bnd.xml file.
<?xml version="1.0" encoding="UTF-8"?>
<managed-bean-bnd 
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  xmlns="http://websphere.ibm.com/xml/ns/javaee"
  xsi:schemaLocation="http://websphere.ibm.com/xml/ns/javaee http://websphere.ibm.com/xml/ns/javaee/ibm-managed-bean-bnd_1_0.xsd"
  version="1.0"
>
  <managed-bean class="com.ibm.example.MyManagedBean">
    <resource-ref name="myDS" binding-name="jdbc/ds1"/>
    <resource-ref name="com.ibm.example.MyManagdBean/field" binding-name="jdbc/ds2"/>
    <message-destination-ref name="myQueue" binding-name="jms/mqQueue"/>
    <ejb-ref name="myEJB" binding-name="java:app/MyEJBModule/MyStatelessBean"/>
  </managed-bean>

  <interceptor class="com.ibm.example.MyManagedBeanInterceptor">
    <resource-ref name="interceptorDS" binding-name="jdbc/db2ds"/>
  </interceptor>
</managed-bean-bnd>

As defined by the managed bean binding schema, the ibm-managed-bean-bnd.xml file shares a subset of common element definitions with EJB bindings.

For a list of the EJB binding elements and their descriptions, see the EJB 3.0 and EJB 3.1 application bindings overview page.


指出主題類型的圖示 概念主題



時間戳記圖示 前次更新: July 9, 2016 11:10
http://www14.software.ibm.com/webapp/wsbroker/redirect?version=cord&product=was-nd-mp&topic=cejb_managedbeans
檔名:cejb_managedbeans.html