Uploaded image for project: 'Weld'
  1. Weld
  2. WELD-2653

Almost, but not quite empty SE-container throws exception on missing beans.xml

    XMLWordPrintable

Details

    • Bug
    • Resolution: Not a Bug
    • Major
    • None
    • 3.1.5.Final
    • Java SE Support
    • None
    • Hide

      Run this JUnit5 test:

      package com.example;
      
      import org.jboss.weld.junit5.WeldInitiator;
      import org.jboss.weld.junit5.WeldSetup;
      import org.jboss.weld.junit5.auto.EnableAutoWeld;
      import org.junit.jupiter.api.Assertions;
      import org.junit.jupiter.api.Test;
      
      import javax.enterprise.context.Dependent;
      import javax.enterprise.event.Observes;
      import javax.enterprise.inject.spi.AfterBeanDiscovery;
      import javax.enterprise.inject.spi.Extension;
      
      @EnableAutoWeld
      public class BugHunt5000 {
      
          @WeldSetup
          WeldInitiator weld = WeldInitiator.from(MyExtension.class).build();
      
          @Test
          public void dummy () {
              Assertions.assertEquals(42, weld.select(Integer.class).get());
          }
      }
      
      class MyExtension implements Extension{
      
          private void addBean(@Observes AfterBeanDiscovery abd){
              abd.addBean()
                 .types(Integer.class)
                 .scope(Dependent.class)
                 .produceWith(__ -> 42);
          }
      }
      

      A workaround exists: Just add a dummy bean class to the WeldInitiator.

      Show
      Run this JUnit5 test: package com.example; import org.jboss.weld.junit5.WeldInitiator; import org.jboss.weld.junit5.WeldSetup; import org.jboss.weld.junit5.auto.EnableAutoWeld; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import javax.enterprise.context.Dependent; import javax.enterprise.event.Observes; import javax.enterprise.inject.spi.AfterBeanDiscovery; import javax.enterprise.inject.spi.Extension; @EnableAutoWeld public class BugHunt5000 { @WeldSetup WeldInitiator weld = WeldInitiator.from(MyExtension.class).build(); @Test public void dummy () { Assertions.assertEquals(42, weld.select( Integer .class).get()); } } class MyExtension implements Extension{ private void addBean(@Observes AfterBeanDiscovery abd){ abd.addBean() .types( Integer .class) .scope(Dependent.class) .produceWith(__ -> 42); } } A workaround exists: Just add a dummy bean class to the WeldInitiator.
    • Undefined

    Description

      A Weld SE-Container that has bean discovery disabled, no bean classes, no packages to scan and only extensions, throws an IllegalStateException upon start, because beans.xml is missing:

      WELD-ENV-000016: Missing beans.xml file in META-INFWELD-ENV-000016: Missing beans.xml file in META-INFjava.lang.IllegalStateException: WELD-ENV-000016: Missing beans.xml file in META-INF at org.jboss.weld.environment.se.Weld.initialize(Weld.java:773) at org.jboss.weld.junit.AbstractWeldInitiator.initWeldContainer(AbstractWeldInitiator.java:502) at org.jboss.weld.junit5.WeldInitiator.initWeld(WeldInitiator.java:193) at org.jboss.weld.junit5.WeldJunit5Extension.starWeldContainerIfAppropriate(WeldJunit5Extension.java:272) at org.jboss.weld.junit5.WeldJunit5Extension.beforeEach(WeldJunit5Extension.java:200) at [...]
      

      This is a problem in situations where I want the only beans to come from the extension(s), for example in a JUnit-test for the extension(s).

       

      Attachments

        Activity

          People

            Unassigned Unassigned
            johannes-hahn Johannes Hahn (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: