3 Replies Latest reply on Aug 3, 2011 7:10 AM by Alex Ander

    CDI inside do not work inside WEB-INF/lib of WAR-App

    Alex Ander Newbie

      Hi @ll,

       

      after searching in forums and reading this article: https://docs.jboss.org/author/display/AS7/Class+Loading+in+AS7

      I could not solve my problem, maybe u can help.

       

      I have following 3 classes in module.jar:

       

      JaxRsActivator.java

       

      @ApplicationPath("/social/rest")

      public class JaxRsActivator extends Application {

         /* class body intentionally left blank */

      }

       

      Resources.java

       

      public class Resources {

                // use @SuppressWarnings to tell IDE to ignore warnings about field not

                // being referenced directly

                @SuppressWarnings("unused")

                @Produces

                @PersistenceContext(unitName = "myUnit1")

                private EntityManager em;

       

       

                @Produces

                Logger getLog(InjectionPoint ip) {

                          String category = ip.getMember().getDeclaringClass().getName();

                          return Logger.getLogger(category);

                }

      }

       

      StatisticResourceRESTService.java

       

      @Path("/statistic")

      @RequestScoped

      @Stateful

      public class StatisticResourceRESTService {

       

      @Inject

                private EntityManager em;

       

                @Inject

                private Logger log;

       

      [...]

       

      @GET

                @Path("/test")

                @Produces({ MediaType.TEXT_PLAIN })

                @GZIP

                public Response retrieveTest(

                                    @HeaderParam("X-Request-Id") final String requestId,

                                    @Context final Request request) {

                          Variant variant = VariantsBuilder.buildVariant(request, new String[]{MediaType.TEXT_PLAIN});

                          String s = new String("Hello with umlauts äöü!!!");

                          log.info(s);

                          ResponseBuilder builder = Response.status(Response.Status.OK);

                    builder.variant(variant);

                    builder.entity(s);

                    return builder.build();

                }

       

      1.

      If i deploy this 3 classes inside module.war/WEB-INF/classes/../*.class

      the CDI of em and log works fine!!!

       

      2.

      If I deploy the module.jar inside the module.war/WEB-INF/lib/module.jar.

      The deployment fail with:

      WELD-001408 Unsatisfied dependencies for type [EntityManager] with qualifiers [@Default] at injection point [[field] @Inject private...

      same for Log

       

      Whats wrong here? What should I do to get the CDI in case 2 to run.

       

      !!! I can access the REST service in both cases, but in case 2 i get NullPointerException at log.info...

       

      many thx

      regards

      Alex