6 Replies Latest reply on Oct 30, 2014 10:16 PM by rogerparkinson

    Trying to disable @EJB and @PersistentContext

    rogerparkinson

      Is there a way to stop the @EJBs and  @PersistenceContext annotations my classes actually doing anything?

      I know this sounds odd. But I have a couple of jar files I'm dependent on and they have a pile of beans defined and @PersistentContexts as well.

      They're quite big (and arguably should be smaller) and what I'm calling doesn't go near those beans etc, so I just want to render them inactive.

      The war file I'm building doesn't actually use any beans or auto injection, so turning it all off won't break my own stuff.

      I've got this in my jboss-deployment-structure:

      <jboss-deployment-structure>

        <deployment>

          <exclude-subsystems>

            <subsystem name="weld" />

          </exclude-subsystems>

        </deployment>

      </jboss-deployment-structure>

      and I have no beans.xml, so I'm fairly sure weld isn't doing anything here.

      Thanks for any help

       

      Wildfly 8.1.0-Final

        • 1. Re: Trying to disable @EJB and @PersistentContext
          rogerparkinson

          I have found an answer but not one I like much.

          I can edit standalone.xml and comment out the ejb and jpa stuff.

          That works but, of course, if I want to deploy another war file which does use JPA I can't, or not on that server anyway.

          So I'm happy to hear a better answer.

          • 2. Re: Trying to disable @EJB and @PersistentContext
            jaikiran

            There's a portable way of doing this. Just set the metadata-complete attribute to true in the deployment descriptor of your application. The application.xml, web.xml and ejb.xml all have that attribute on their root element. Take a look at the relevant xsd to get it right. Setting it to true, tells the container to ignore any annotation based components and instead rely just on the deployment descriptors for components.

            • 3. Re: Trying to disable @EJB and @PersistentContext
              rogerparkinson

              When I try metadata-complete it fails to deploy:

              18:32:30,732 INFO  [org.jboss.as.jpa] (MSC service thread 1-11) JBAS011401: Read persistence.xml for ghiDatabase

              18:32:30,858 ERROR [org.jboss.as.controller.management-operation] (DeploymentScanner-threads - 1) JBAS014613: Operation ("deploy") failed - address: ([("deployment" => "com.ghiplus.knowledge.res.war")]) - failure description: {"JBAS014771: Services with missing/unavailable dependencies" => ["jboss.persistenceunit.\"com.ghiplus.knowledge.res.war#ghiDatabase\".__FIRST_PHASE__ is missing [jboss.naming.context.java.jdbc.ghi]"]}

               

              So it is still looking for the persistence stuff. What I did was add metadata-complete="true" to the web-app tag in my web.xml file.

              I'm okay with the edits in the standalone, though.

              • 4. Re: Trying to disable @EJB and @PersistentContext
                jaikiran

                That doesn't look like an annotation based issue. It looks like your application (war?) has a persistence.xml which is expecting a datasource at certain JNDI name. You'll either have to setup that datasource or remove that persistence.xml if you don't need it.

                • 5. Re: Trying to disable @EJB and @PersistentContext
                  rogerparkinson

                  That is the case. The persistence.xml is inside a jar file I am dependent on, and I don't have control over.

                  Okay, well I can go with the edit of standalone.xml then, and I understand what is happening too.

                  Thanks

                  • 6. Re: Trying to disable @EJB and @PersistentContext
                    rogerparkinson

                    I made more progress and I have it solved now. This is what I needed to do:

                    1) add metadata-complete="true" to the web-app tag in my web.xml file (as suggested by Jaikiran Pai). This suppresses instantiating beans I don't need.

                    2) add <subsystem name="jpa" /> to the exclusions in jboss-deployment-structures.xml. That suppresses the persistence.xml file triggering a database requirement.

                    3) I also added a dependency to hibernate.core because it complained about a missing org.hibernate.exception.SQLGrammarException

                     

                    Now it loads with an unedited standalone.xml file