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

Weld docs incorrectly state that @ManagedBean can be used to mark a class a managed CDI bean

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major Major
    • 5.1.1.Final
    • 5.1.0.Final
    • Documentation
    • None
    • Hide

      Single

      @ManagedBean
      public class AppController{
          public static void main(String[] args){
              SeContainerInitializer.newInstance().initialize();
          }
      } 

      ...crashes:

      Exception in thread "main" java.lang.IllegalStateException: WELD-ENV-002009: Weld SE container cannot be initialized - no bean archives found

      Show
      Single @ManagedBean public class AppController{     public static void main( String [] args){         SeContainerInitializer.newInstance().initialize();     } } ...crashes: Exception in thread "main" java.lang.IllegalStateException: WELD-ENV-002009: Weld SE container cannot be initialized - no bean archives found

      The single

      @ManagedBean
      public class BeanType{} 

      is bypassed on SeContainerInitializer.newInstance().initialize(), since the jakarta.annotation.@ManagedBean annotation(from weld-se-shaded-5.1.0.Final.jar!) is not included into 'final Set<Class<? extends Annotation>> beanDefiningAnnotations' of Weld.createDeployment(...), leading to 'WELD-ENV-002009: Weld SE container cannot be initialized - no bean archives found' startup crash.

      Things become much better if @ManagedBean is replaced with something from the beanDefiningAnnotations set, e.g. @ApplicationScoped.

      the https://docs.jboss.org/weld/reference/latest/en-US/html_single/#_managed_beans states "You can explicitly declare a managed bean by annotating the bean class @ManagedBean, but in CDI you don’t need to." @ManagedBean classes muzz be managed by Weld and so trigger isBeanArchive flag when framework scans their container.

       

              manovotn Matěj Novotný
              spamcollector Dmitriy Kuznetsov (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved: