1 Reply Latest reply on May 19, 2014 4:16 AM by mkouba

    Play Framework with weld

    paincraft

      hi all, i'm trying to use weld 2.2 container in Play Framework but i'm getting error:

      ClassCastException: org.jboss.weld.bootstrap.WeldBootstrap cannot be cast to org.jboss.weld.bootstrap.api.CDI11Bootstrap
      
      


      Below you will find my Global.java (wled crashes at container initialization):

       

      public class Global extends GlobalSettings {
      
          private WeldContainer weld;
      
          @Override
          public void onStart(Application app) {
              weld = new Weld().initialize();
          }
      
          @Override
          public void onStop(Application app) {
              shutdown(weld);
          }
      
          @Override
          public <A> A getControllerInstance(Class<A> clazz) {
              return weld.instance().select(clazz).get();
          }
      
          private void shutdown(WeldContainer weld) {
              ShutdownManager shutdownManager = weld.instance().select(ShutdownManager.class).get();
              shutdownManager.shutdown();
          }
      }
      
      

       

      Anyone could help ?

       

      Update:

      Same problem with Java SE CDI

       

      public class RuntimeEnvironmentProducerTest {    
          @Inject
          RuntimeEnvironmentProducer environment;
          
          public void runTest(){
              if(environment != null){
                  System.out.println("environment ok");
              }else{
                  System.out.println("environment not ok");
              }
          }
      }
      

       

      public class MainTests {
          
            public static void main(String[] args) throws IOException {
                
                 Weld weld = new Weld();
                 WeldContainer container = weld.initialize();
                 
                 RuntimeEnvironmentProducerTest runtimeEnvironmentProducerTest 
                     = container.instance().select(RuntimeEnvironmentProducerTest.class).get();
                 
                 runtimeEnvironmentProducerTest .runTest();
                 
                 weld.shutdown();
               
                }
      }
      
      Output:
      12:28:12.939 [main] DEBUG org.jboss.logging - Logging Provider: org.jboss.logging.Slf4jLoggerProvider
      12:28:13.024 [main] INFO  org.jboss.weld.Version - WELD-000900 1.1.13 (Final)
      Exception in thread "main" java.lang.ClassCastException: org.jboss.weld.bootstrap.WeldBootstrap cannot be cast to org.jboss.weld.bootstrap.api.CDI11Bootstrap
          at org.jboss.weld.environment.se.Weld.initialize(Weld.java:120)
          at producersTests.MainTests.main(MainTests.java:17)
      
        • 1. Re: Play Framework with weld
          mkouba

          Hi Radosław,

          First, I can see "WELD-000900 1.1.13 (Final)" in the log. It seems you have multiple Weld versions on the classpath. Make sure you only have Weld 2.2 on the classpath (e.g. use mvn dependency:tree). Also your Global class shutdown method should be fixed - you can't inject/lookup the correct ShutdownManager, instead invoke org.jboss.weld.environment.se.Weld#shutdown() directly.