glassfish
  1. glassfish
  2. GLASSFISH-20912

Unable to find object in CDI using @Produces with no beans.xml

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Works as designed
    • Affects Version/s: 4.0
    • Fix Version/s: None
    • Component/s: cdi
    • Labels:
      None

      Description

      Given a Java bean

      public class Bean {
      private String message;

      public String getMessage()

      { return message; }

      // ...
      }

      and a @Produces method

      public class ObjectFactory {
      @Produces
      public Bean createBean()

      { final Bean bean = new Bean(); bean.setMessage("Hello CDI"); return bean; }

      }

      Doing an injection yields.

      javax.servlet.ServletException: A MultiException has 1 exceptions. They are:
      1. org.glassfish.hk2.api.UnsatisfiedDependencyException: There was no object available for injection at Injectee(requiredType=Bean,parent=AppResource,qualifiers={}),position=-1,optional=false,self=false,unqualified=null,2080834135)

      I have tried other combinations with @Dependent on the ObjectFactory and on the bean itself with no luck.

      I also tried it with a @Qualifier also no luck. However, I can get it working when beans.xml with bean-discovery-mode="all"

        Activity

        Hide
        jjsnyder83 added a comment -

        Please provide the code that shows the injection point.

        Show
        jjsnyder83 added a comment - Please provide the code that shows the injection point.
        Hide
        jjsnyder83 added a comment -

        Add @Dependent to the Bean class. Since there is no beans.xml implicit CDI is being used and therefore only beans with bean defining annotations will be recognized and managed. Adding @Dependent forces Bean to be a cdi-managed bean.

        Show
        jjsnyder83 added a comment - Add @Dependent to the Bean class. Since there is no beans.xml implicit CDI is being used and therefore only beans with bean defining annotations will be recognized and managed. Adding @Dependent forces Bean to be a cdi-managed bean.

          People

          • Assignee:
            jjsnyder83
            Reporter:
            atrajano
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: