0 Replies Latest reply on Dec 27, 2012 7:06 AM by Andrew Winter

    Injecting custom resource factory with @Resource

    Andrew Winter Newbie

      Dear JBoss Experts

       

      I want to inject my own resource factory into a RESTful service using @Resource. For example,

       

      @ApplicationPath("/foo/")

      @Path("/")

      class Foo extends Application {

                @Resource

                private MyFactory factory;

      }

       

      I've created a deployment unit processor that registers a new resource reference processor with EEResourceReferenceProcessorRegistry, like this:

       

      public void deploy(DeploymentPhaseContext dpc) throws DeploymentUnitProcessingException {

              EEResourceReferenceProcessorRegistry registry = dpc.getDeploymentUnit().getAttachment(

                      Attachments.RESOURCE_REFERENCE_PROCESSOR_REGISTRY);

              registry.registerResourceReferenceProcessor(new MyFactoryResourceReferenceProcessor());

      }

       

      My DUP is installed in phase POST_MODULE with priority 0 so it gets executed before ResourceInjectionAnnotationParsingProcessor.

       

      The problem is, injection is not happening. When I  invoke a method on my web service I get the error:

       

                javax.naming.NameNotFoundException: env/com.acme.WebService/factory

       

      ResourceInjectionAnnotationParsingProcessor seems to be creating a BindingConfiguration using local context name "com.acme.WebService/factory" and the correct value source but the BindingConfiguration is added to the class description, like this:

       

                DeploymentUnit deploymentUnit = dpc.getDeploymentUnit();

                EEModuleDescription eeModuleDescription = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);

                EEModuleClassDescription classDescription = eeModuleDescription.addOrGetLocalClassDescription("com.acme.WebService");

                classDescription.getBindingConfigurations().add(bindingConfiguration);

       

      but if the binding is added to the module description, like this, injection works:

       

                DeploymentUnit deploymentUnit = dpc.getDeploymentUnit();

                EEModuleDescription eeModuleDescription = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);

                eeModuleDescription.getBindingConfigurations().add(bindingConfiguration);

       

      Can anyone point me in the right direction?

       

      I'm using JBoss 7.1.1.Final. My deployment unit is a WAR. I've got an empty beans.xml file and CDI generally is working.

       

      Thanks all

       

      Andrew.