Uploaded image for project: 'Application Server 3  4  5 and 6'
  1. Application Server 3 4 5 and 6
  2. JBAS-7190

'More than one post-construct method'-Exception when @PostContruct method is overloaded

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Obsolete
    • Icon: Major Major
    • No Release
    • JBossAS-5.1.0.GA
    • EJB
    • None
    • JBoss 5.1.0.GA, JDK6

    • Workaround Exists
    • Hide

      Don't overload routines annotated with @PostConstruct. The workaround applied to the example above results in:
      @Stateless
      public class AccessorBean implements AccessorLocal {
      [...]
      public AccessorBean() {
      }

      @PostConstruct
      public void initialize()

      { this.init(em, cache); }

      private void init(EntityManager em,
      Cache cache)

      { accessor = new EntityAccessorJPA(em); accessor.setCache(cache); }

      [..]
      }

      Show
      Don't overload routines annotated with @PostConstruct. The workaround applied to the example above results in: @Stateless public class AccessorBean implements AccessorLocal { [...] public AccessorBean() { } @PostConstruct public void initialize() { this.init(em, cache); } private void init(EntityManager em, Cache cache) { accessor = new EntityAccessorJPA(em); accessor.setCache(cache); } [..] }

      I have a stateless session bean with a initialize() routine that is annotated with a @PostConstruct annotation. The intialize() routine is overloaded but the overloaded routine doesn't have a @PostConstruct annotation, like this:

      @Stateless
      public class AccessorBean implements AccessorLocal {
      public AccessorBean() {
      }

      @PostConstruct
      public void initialize()

      { this.initialize(em, cache); }

      private void initialize(EntityManager em, Cache cache)

      { accessor = new EntityAccessorJPA(em); accessor.setCache(cache); }

      [..]
      }

      When I access my bean I get the following RuntimeException:

      javax.ejb.EJBTransactionRolledbackException: java.lang.RuntimeException: More than one 'post-construct' method in AccessorBean
      at org.jboss.ejb3.tx.Ejb3TxPolicy.handleInCallerTx(Ejb3TxPolicy.java:115)
      at org.jboss.aspects.tx.TxPolicy.invokeInCallerTx(TxPolicy.java:130)
      at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:194)
      at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
      at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)
      at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
      at org.jboss.ejb3.security.RunAsSecurityInterceptorv2.invoke(RunAsSecurityInterceptorv2.java:94)
      [...]
      Caused by: java.lang.RuntimeException: java.lang.RuntimeException: More than one 'post-construct' method in AccessorBean
      at org.jboss.ejb3.EJBContainer.invokeCallback(EJBContainer.java:1123)
      at org.jboss.ejb3.EJBContainer.invokePostConstruct(EJBContainer.java:1133)
      at org.jboss.ejb3.EJBContainer.invokePostConstruct(EJBContainer.java:1144)
      at org.jboss.ejb3.pool.AbstractPool.create(AbstractPool.java:93)
      at org.jboss.ejb3.InfinitePool.get(InfinitePool.java:56)
      at org.jboss.ejb3.InfinitePool.get(InfinitePool.java:51)
      at org.jboss.ejb3.pool.ThreadlocalPool.create(ThreadlocalPool.java:53)
      at org.jboss.ejb3.pool.ThreadlocalPool.get(ThreadlocalPool.java:93)
      at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:58)
      at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
      at org.jboss.aspects.tx.TxPolicy.invokeInCallerTx(TxPolicy.java:126)
      ... 82 more
      Caused by: java.lang.RuntimeException: More than one 'post-construct' method in AccessorBean
      at org.jboss.ejb3.interceptors.aop.LifecycleCallbacks.checkClass(LifecycleCallbacks.java:135)
      at org.jboss.ejb3.interceptors.aop.LifecycleCallbacks.createLifecycleCallbackInterceptors(LifecycleCallbacks.java:103)
      at org.jboss.ejb3.EJBContainer.invokeCallback(EJBContainer.java:1112)
      ... 92 more

      But I annotated only one routine with the @PostContruct annotation. The reason for this seams to be the overloaded initialize() routine. If I don't overload it everything is fine.

      This seems to be a bug in JBoss5. Maybe the checkClass() routine in the LifecycleCallbacks class assumes that every overloaded method of a with an @PostConstruct annotated method has also a @PostContruct annotation.

              rhn-engineering-cdewolf Carlo de Wolf
              mathiasarens3 Mathias Arens (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated:
                Resolved: