이 콘텐츠는 선택한 언어로 제공되지 않습니다.

5.4. Lifecycle Callbacks


In addition to applying aspects to beans that we instantiate using the Microcontainer we can also add behavior during the deployment and undeployment process. As mentinoed in Section 4.3, “Direct Access”, a bean goes through several different states as it is deployed. These include:
NOT_INSTALLED
the deployment descriptor containing the bean has been parsed, along with any annotations on the bean itself.
DESCRIBED
any dependencies created by AOP have been added to the bean, and custom annotations have been processed.
INSTANTIATED
an instance of the bean has been created.
CONFIGURED
properties have been injected into the bean, along with any references to other beans.
CREATE
the create method, if defined in the bean, has been called.
START
the start method, if defined in the bean, has been called.
INSTALLED
any custom install actions that were defined in the deployment descriptor have been executed and the bean is ready to access.

Important

The CREATE and START states are included for legacy purposes. This allows services that were implemented as MBeans in previous versions of the Enterprise Platform to function correctly when implemented as beans in the Enterprise Platform 5.1. If you do not define any corresponding create/start methods in your bean, it will pass straight through these states.
These states represent the bean's lifecycle. You can define a number of callbacks to be applied to any point by using an additional set of <aop> elements:
<aop:lifecycle-describe>
applied when entering/leaving the DESCRIBED state
<aop:lifecycle-instantiate>
applied when entering/leaving the INSTANTIATED state
<aop:lifecycle-configure>
applied when entering/leaving the CONFIGURED state
<aop:lifecycle-create>
applied when entering/leaving the CREATE state
<aop:lifecycle-start>
applied when entering/leaving the START state
<aop:lifecycle-install>
applied when entering/leaving the INSTALLED state
Like the <bean> and <aop:aspect> elements, the <aop:lifecycle-> elements contain name and class attributes. The Microcontainer uses these attributes to create an instance of the callback class, naming it so that it can be used as beans enter or leave the relevant state during deployment and undeployment. You can specify which beans are affected by the callback using the classes attribute, as shown in Example 5.5, “Using the classes Attribute”.

Example 5.5. Using the classes Attribute

<aop:lifecycle-install xmlns:aop="urn:jboss:aop-beans:1.0"

name="InstallAdvice"

class="org.jboss.test.microcontainer.support.LifecycleCallback"

classes="@org.jboss.test.microcontainer.support.Install">

</aop:lifecycle-install>
			
			
			
			

Copy to Clipboard Toggle word wrap
This code specifies that additional logic in the lifecycleCallback class is applied to any bean classes that are annotated with @org.jboss.test.microcontainer.support.Install before they enter and after they leave the INSTALLED state.
For the callback class to work, it must contain install and uninstall methods that take ControllerContext as a parameter, as shown in Example 5.6, “Install and Uninstall Methods”.

Example 5.6. Install and Uninstall Methods

import org.jboss.dependency.spi.ControllerContext;

public class LifecycleCallback {

    public void install(ControllerContext ctx) {
        System.out.println("Bean " + ctx.getName() + " is being installed";
    }
    public void uninstall(ControllerContext ctx) {
	    System.out.println("Bean " + ctx.getName() + " is being uninstalled";
    }
}
			
			
			
			

Copy to Clipboard Toggle word wrap
The install method is called during the bean's deployment, and the uninstall method during its undeployment.

Note

Although behavior is being added to the deployment and undeployment process using callbacks, AOP is not actually used here. The pointcut expression functionality of JBoss AOP is used to determine which bean classes the behaviors apply to.
맨 위로 이동
Red Hat logoGithubredditYoutubeTwitter

자세한 정보

평가판, 구매 및 판매

커뮤니티

Red Hat 문서 정보

Red Hat을 사용하는 고객은 신뢰할 수 있는 콘텐츠가 포함된 제품과 서비스를 통해 혁신하고 목표를 달성할 수 있습니다. 최신 업데이트를 확인하세요.

보다 포괄적 수용을 위한 오픈 소스 용어 교체

Red Hat은 코드, 문서, 웹 속성에서 문제가 있는 언어를 교체하기 위해 최선을 다하고 있습니다. 자세한 내용은 다음을 참조하세요.Red Hat 블로그.

Red Hat 소개

Red Hat은 기업이 핵심 데이터 센터에서 네트워크 에지에 이르기까지 플랫폼과 환경 전반에서 더 쉽게 작업할 수 있도록 강화된 솔루션을 제공합니다.

Theme

© 2025 Red Hat