4 Replies Latest reply on Dec 11, 2009 11:31 PM by Drew Arrigoni

    Dependency Injection

    Drew Arrigoni Newbie

      So, I'm in the process of learning Weld in its most basic form. I got Weld seeming to deploy correctly and so forth for Tomcat. However, my Injection doesn't seem to be working for my servlet.


      Here's my stack trace:


      javax.enterprise.inject.UnsatisfiedResolutionException: class com.test.weld.HelloSayer; binding types = [@Default]Unable to resolve any Managed Beans
           org.jboss.weld.BeanManagerImpl.getBean(BeanManagerImpl.java:1074)
           org.jboss.weld.BeanManagerImpl.getInjectableReference(BeanManagerImpl.java:1040)
           org.jboss.weld.injection.FieldInjectionPoint.inject(FieldInjectionPoint.java:92)
           org.jboss.weld.util.Beans.injectBoundFields(Beans.java:727)
           org.jboss.weld.util.Beans.injectFieldsAndInitializers(Beans.java:739)
           org.jboss.weld.SimpleInjectionTarget$1.proceed(SimpleInjectionTarget.java:115)
           org.jboss.weld.injection.InjectionContextImpl.run(InjectionContextImpl.java:51)
           org.jboss.weld.SimpleInjectionTarget.inject(SimpleInjectionTarget.java:109)
           org.jboss.weld.environment.tomcat.WeldAnnotationProcessor.processAnnotations(WeldAnnotationProcessor.java:38)
           org.jboss.weld.environment.tomcat.WeldLifecycleListener$2.processAnnotations(WeldLifecycleListener.java:51)
           org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
           org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
           org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
           org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
           org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
           java.lang.Thread.run(Thread.java:636)



      And here're my two classes...


      package com.test.weld;
      
      
      public class HelloSayer {
           
           public String sayHello(String input) {
                return "Hello " + input + "!";
           }
      
      }



      package com.test.weld;
      
      import java.io.IOException;
      
      import javax.inject.Inject;
      import javax.servlet.ServletException;
      import javax.servlet.http.HttpServlet;
      import javax.servlet.http.HttpServletRequest;
      import javax.servlet.http.HttpServletResponse;
      
      /**
       * Servlet implementation class HelloWeldServlet
       */
      public class HelloWeldServlet extends HttpServlet {
           private static final long serialVersionUID = 1L;
           
           @Inject HelloSayer helloSayer;
      
           protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
                response.setContentType("text/plain");
                response.getWriter().write(helloSayer.sayHello("Weld"));
           }
      
      }




      I'm pretty sure there's something completely retarded I'm not doing right.