[jboss-jira] [JBoss JIRA] Commented: (JBAS-7236) @PostConstruct is never called for @Service beans

Gregory Mostizky (JIRA) jira-events at lists.jboss.org
Tue Sep 15 05:40:36 EDT 2009


    [ https://jira.jboss.org/jira/browse/JBAS-7236?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12485793#action_12485793 ] 

Gregory Mostizky commented on JBAS-7236:
----------------------------------------

I've digged into the code (5.1.0 GA sources) and I think I found both the cause of this and also a workaround:

In org.jboss.ejb3.service.ServiceContainer which is responsible for lifecycle of @Service beans there are following lines:

<code>
   public void invokePostConstruct(BeanContext beanContext, Object[] params)
   {
      //Ignore
   }

   public void invokePreDestroy(BeanContext beanContext)
   {
      //Ignore
   }
</code>

Because of this the container will not invoke @PostConstruct and @PreDestroy even if it sees them.

On the other hand there is a workaround. 

<code>
   public void create() throws Exception
   {
      super.create();

      // EJBTHREE-655: fire up an instance for use as MBean delegate
      singleton = super.construct();

      registerManagementInterface();

      invokeOptionalMethod(METHOD_NAME_LIFECYCLE_CALLBACK_CREATE);
   }
</code>

What happens here is that after the bean is created there is hardcoded call to a method with "public void create()" signature if it's found.
Similar is done for destroy. 

In other words if you define an initialization like this it will get called now and when the bug is fixed.

<code>
@PostConstruct
public void create() {
}
</code>





> @PostConstruct is never called for @Service beans
> -------------------------------------------------
>
>                 Key: JBAS-7236
>                 URL: https://jira.jboss.org/jira/browse/JBAS-7236
>             Project: JBoss Application Server
>          Issue Type: Bug
>      Security Level: Public(Everyone can see) 
>          Components: EJB3
>    Affects Versions: JBossAS-5.1.0.GA
>         Environment: JBoss 5.1.0 GA running of Fedora Core 11
>            Reporter: Gregory Mostizky
>            Assignee: Carlo de Wolf
>
> I have a @Service bean which defines initialization method and that method is marked with @PostConstruct.
> This method is never called by JBoss, not when the bean is first created and not when it is accessed.
> Same issue happens when testing with embedded jboss (beta3.sp9)

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: https://jira.jboss.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        



More information about the jboss-jira mailing list