2 Replies Latest reply on Jan 23, 2014 9:09 AM by flowersinthesand

    Injection fails in ServerApplicationConfig

    flowersinthesand

      I've tried to inject some bean to javax.websocket.server.ServerApplicationConfig instance to be scanned and instantiated by container but it doesn't work.

       

      Use case

      I need to make some bean be available to ServletContextListener and ServerApplicationConfig to handle HTTP request and WebSocket together. Although I made it static, I'd like to try graceful solution using CDI. Spring and Guice can't help here because they are created by container.

      portal-java-examples/server/platform/jee7/src/main/java/io/github/flowersinthesand/portal/testsuite/Bootstrap.java at ma…

       

      To reproduce

      I used wildfly-maven-plugin

      <plugin>
           <groupId>org.wildfly.plugins</groupId>
           <artifactId>wildfly-maven-plugin</artifactId>
           <version>1.0.0.Beta1</version>
           <configuration>
                <jvmArgs>-Dorg.jboss.as.logging.per-deployment=false</jvmArgs>
           </configuration>
      </plugin>
      
      

       

      TestBean.java

      @ApplicationScoped
      public class TestBean {}
      
      

       

      TestServerApplicationConfig.java

      public class TestServerApplicationConfig implements ServerApplicationConfig {
      
      
        @Inject
        TestBean testBean;
      
      
        @Override
        public Set<ServerEndpointConfig> getEndpointConfigs(Set<Class<? extends Endpoint>> endpointClasses) {
        System.out.println("ServerApplicationConfig");
        System.out.println(testBean);
        return null;
        }
      
      
        @Override
        public Set<Class<?>> getAnnotatedEndpointClasses(Set<Class<?>> scanned) {
        return null;
        }
      
      
      }
      
      

       

      TestServletContextListener.java

      @WebListener
      public class TestServletContextListener implements ServletContextListener {
      
        @Inject
        TestBean testBean;
      
      
        @Override
        public void contextInitialized(ServletContextEvent sce) {
        System.out.println("ServletContextListener");
        System.out.println(testBean);
        }
      
      
        @Override
        public void contextDestroyed(ServletContextEvent sce) {}
      
      
      }
      
      

       

      And the result:

      21:09:49,507 INFO  [stdout] (MSC service thread 1-4) ServerApplicationConfig

      21:09:49,508 INFO  [stdout] (MSC service thread 1-4) null

      21:09:50,776 INFO  [org.jboss.weld.deployer] (MSC service thread 1-6) JBAS016005: Starting Services for CDI deployment: portal-example-0.war

      21:09:51,550 INFO  [org.jboss.weld.Version] (MSC service thread 1-6) WELD-000900: 2.1.0 (CR1)

      21:09:51,838 INFO  [org.jboss.weld.deployer] (MSC service thread 1-6) JBAS016008: Starting weld service for deployment portal-example-0.war

      21:09:57,273 INFO  [stdout] (MSC service thread 1-5) ServletContextListener

      21:09:57,284 INFO  [stdout] (MSC service thread 1-5) io.github.flowersinthesand.portal.example.TestBean@16acb345

      21:09:58,689 INFO  [org.wildfly.extension.undertow] (MSC service thread 1-5) JBAS018210: Register web context: /portal-example-0

      21:09:59,679 INFO  [org.jboss.as.server] (management-handler-thread - 4) JBAS018559: Deployed "portal-example-0.war" (runtime-name : "portal-example-0

      .war")

       

      As you can see, CDI service starts after instantiation of ServerApplicationConfig. Is this expected or bug?

       

      Thanks,