4 Replies Latest reply on Sep 26, 2017 6:53 AM by manovotn

    @PostConstruct method not called on CDI bean from external deployment module

    per.norrman

      Using wildfly 10.1.0.Final, I have a problem with CDI beans defined in external modules (looks like bug).

       

      I have simple rest web application (test-app.war) where a service is injected with a bean that is defined in an external module (test.service). This dependency is declared in a jboss-deployment-structure.xml file:

       

      <jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2">
          <deployment>
              <dependencies>
                  <module name="test.service" meta-inf="import"/>
              </dependencies>
          </deployment>
      </jboss-deployment-structure>
      

       

      The bean implementation:

       

      @ApplicationScoped
      public class MessageProducerImpl implements MessageProducer {
           private Status status = Status.UNDEFINED;
      
          @PostConstruct
          private void init() { this.status = Status.INITIALIZED; }
      
          public Status status() { return status; }
      }
      

       

      The implementation lives in the test.service module, which also has module dependencies to org.jboss.weld.core and org.jboss.weld.spi. After deploying the module and the webapp, wildfly starts ok with no error messages. The service is injected and invoked like this:

       

      @Path("/")
      @ApplicationScoped
      public class MessageResource {
              
          @Inject
          MessageProducer messageProducer;
      
          @GET
          @Path("/status")
          public Response status() {
            String result = messageProducer.status() + "\n";
            return Response.status(200).entity(result).build();
          }
      }
      

       

      I would've expected that invoking this resource should return INITIALIZED, but it returns UNDEFINED, i.e. the init() method of the bean has not been called. If I package the external module jar directly in the webapp, INITIALIZED is returned.

      Have I forgotten anything?

       

      Cheers,

      Per Norrman