Uploaded image for project: 'ModeShape'
  1. ModeShape
  2. MODE-1813

Using CDI to inject Session results in ClassNotFoundException for org.xml.sax.ContentHandler in JBoss AS 7

    XMLWordPrintable

Details

    Description

      Using the following code to produce JCR Repository and Session instances causes Weld to throw NoClassDefFoundError when my web application is loaded by JBoss AS.

      Stacktrace:

      Caused by: java.lang.ClassNotFoundException: org.xml.sax.ContentHandler from [Module "javax.jcr:main" from local module
      

      CDI Producer Code:

          @Resource(mappedName="java:/jcr/myrepo")
          @Produces
          private Repository repository;
      
          @RequestScoped
          @Produces
          public Session getCurrentSession(final Repository repository) throws RepositoryException {
              return repository.login();
          }
      
          public void logoutSession(@Disposes final Session session) {
              session.logout();
          }
      

      CDI Consumer Code:

      @Inject
      private Session session; // ClassNotFoundException occurs when this class is loaded
      

      On brief inspection, it seems that the JCR Session object has a method that depends on ContentHandler, and thus when Weld tries to access that method by reflection, it was unable to find ContentHandler. (Probably due to the classloader not having loaded the javax.xml dependencies yet)

      It seems that the JBoss AS 7 kit is missing the following in jboss/modules/javax/jcr/main/module.xml:

      <dependencies>
        <module name="javax.api"/>
      </dependencies>
      

      I believe that GTNPORTAL-2593 had the same issue.

      Attachments

        1. Consumer.java
          0.3 kB
        2. Producer.java
          0.7 kB

        Issue Links

          Activity

            People

              hchiorean Horia Chiorean (Inactive)
              herculeszeus_jira Hercules Zeus (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: