Details

    • Type: Bug
    • Status: Resolved (View Workflow)
    • Priority: Minor
    • Resolution: Duplicate Issue
    • Affects Version/s: JBoss AS7 7.2.0.Final
    • Fix Version/s: None
    • Component/s: Batch, Management
    • Labels:
    • Steps to Reproduce:
      Hide

      Consider JBoss/WildFly  "Batch Processing" QuickStart.

      Change JobListener to have this:

          @Resource(lookup="java:app/AppName")
          private String applicationName;
      
          @Override
          public void beforeJob() throws Exception {
              log.info(String.format("Job %s - Execution #%d starting.", jobContext.getJobName(), jobContext.getExecutionId()));
              log.info(String.format("*** Hello, this is AppName '%s' ***", applicationName));
          }
      

      (1) When we start the "import-file" batch job from the web interface, it runs ok and logs:

      2020-07-23 20:39:50,493 INFO  [org.jboss.as.quickstarts.batch.job.listener.JobListener] (Batch Thread - 7) Job import-file - Execution #17 starting.
      2020-07-23 20:39:50,493 INFO  [org.jboss.as.quickstarts.batch.job.listener.JobListener] (Batch Thread - 7) *** Hello, this is AppName 'batch-processing' ***
      

      (2) But if we start it via CLI, by using e.g. this command,

      /deployment=batch-processing.war/subsystem=batch-jberet:start-job(job-xml-name=import-file,properties={fileName=temp-file.txt})

      it will fail and log

      2020-07-23 20:40:43,315 ERROR [org.jberet] (Batch Thread - 8) JBERET000007: Failed to run job import-file, , org.jberet.job.model.Job@54c822a4: java.lang.IllegalStateException: JBERET000600: Failed to create artifact with ref name jobListener.  Ensure CDI beans.xml is present and batch.xml, if any, is configured properly.
              at org.jberet.runtime.context.JobContextImpl.createArtifact(JobContextImpl.java:199)
              at org.jberet.runtime.runner.JobExecutionRunner.createJobListeners(JobExecutionRunner.java:137)
              at org.jberet.runtime.runner.JobExecutionRunner.run(JobExecutionRunner.java:55)
              at org.wildfly.extension.batch.jberet.deployment.BatchEnvironmentService$WildFlyBatchEnvironment$1.run(BatchEnvironmentService.java:180)
              at org.wildfly.extension.requestcontroller.RequestController$QueuedTask$1.run(RequestController.java:494)
              at org.jberet.spi.JobExecutor$2.run(JobExecutor.java:149)
              at org.jberet.spi.JobExecutor$1.run(JobExecutor.java:99)
              at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
              at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
              at java.lang.Thread.run(Thread.java:748)
              at org.jboss.threads.JBossThread.run(JBossThread.java:485)
      Caused by: java.lang.IllegalArgumentException: WFLYWELD0049: Error injecting resource into CDI managed bean. Can't find a resource named java:app/AppName defined on private java.lang.String org.jboss.as.quickstarts.batch.job.listener.JobListener.applicationName
              at org.jboss.as.weld.services.bootstrap.WeldResourceInjectionServices.resolveResource(WeldResourceInjectionServices.java:239)
              at org.jboss.as.weld.services.bootstrap.WeldResourceInjectionServices$1.createResource(WeldResourceInjectionServices.java:183)
              at org.jboss.weld.injection.AbstractResourceInjection.getResourceReference(AbstractResourceInjection.java:49)
              at org.jboss.weld.injection.AbstractResourceInjection.injectResourceReference(AbstractResourceInjection.java:63)
              at org.jboss.weld.util.Beans.injectEEFields(Beans.java:309)
              at org.jboss.weld.injection.producer.ResourceInjector$1.proceed(ResourceInjector.java:68)
              at org.jboss.weld.injection.InjectionContextImpl.run(InjectionContextImpl.java:48)
              at org.jboss.weld.injection.producer.ResourceInjector.inject(ResourceInjector.java:71)
              at org.jboss.weld.injection.producer.BasicInjectionTarget.inject(BasicInjectionTarget.java:117)
              at org.jboss.weld.bean.ManagedBean.create(ManagedBean.java:159)
              at org.jboss.weld.contexts.unbound.DependentContextImpl.get(DependentContextImpl.java:70)
              at org.jboss.weld.bean.ContextualInstanceStrategy$DefaultContextualInstanceStrategy.get(ContextualInstanceStrategy.java:100)
              at org.jboss.weld.bean.ContextualInstance.get(ContextualInstance.java:50)
              at org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:700)
              at org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:723)
              at org.wildfly.extension.batch.jberet.deployment.ArtifactFactoryService.create(ArtifactFactoryService.java:89)
              at org.jberet.creation.ArtifactFactoryWrapper.create(ArtifactFactoryWrapper.java:44)
              at org.jberet.runtime.context.JobContextImpl.createArtifact(JobContextImpl.java:197)
              ... 10 more
      Caused by: javax.naming.NameNotFoundException: java:app/AppName
              at org.jboss.as.naming.InitialContext$DefaultInitialContext.findContext(InitialContext.java:191)
              at org.jboss.as.naming.InitialContext$DefaultInitialContext.lookup(InitialContext.java:235)
              at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:193)
              at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:189)
              at javax.naming.InitialContext.lookup(InitialContext.java:417)
              at javax.naming.InitialContext.lookup(InitialContext.java:417)
              at org.jboss.as.weld.services.bootstrap.WeldResourceInjectionServices.resolveResource(WeldResourceInjectionServices.java:237)
              ... 27 more
      
      Show
      Consider JBoss/WildFly  "Batch Processing" QuickStart . Change JobListener to have this: @Resource(lookup= "java:app/AppName" ) private String applicationName; @Override public void beforeJob() throws Exception { log.info( String .format( "Job %s - Execution #%d starting." , jobContext.getJobName(), jobContext.getExecutionId())); log.info( String .format( "*** Hello, this is AppName '%s' ***" , applicationName)); } (1) When we start the "import-file" batch job from the web interface, it runs ok and logs: 2020-07-23 20:39:50,493 INFO [org.jboss.as.quickstarts.batch.job.listener.JobListener] (Batch Thread - 7) Job import -file - Execution #17 starting. 2020-07-23 20:39:50,493 INFO [org.jboss.as.quickstarts.batch.job.listener.JobListener] (Batch Thread - 7) *** Hello, this is AppName 'batch-processing' *** (2) But if we start it via CLI, by using e.g. this command, /deployment=batch-processing.war/subsystem=batch-jberet:start-job(job-xml-name= import -file,properties={fileName=temp-file.txt}) it will fail and log 2020-07-23 20:40:43,315 ERROR [org.jberet] (Batch Thread - 8) JBERET000007: Failed to run job import -file, , org.jberet.job.model.Job@54c822a4: java.lang.IllegalStateException: JBERET000600: Failed to create artifact with ref name jobListener. Ensure CDI beans.xml is present and batch.xml, if any, is configured properly. at org.jberet.runtime.context.JobContextImpl.createArtifact(JobContextImpl.java:199) at org.jberet.runtime.runner.JobExecutionRunner.createJobListeners(JobExecutionRunner.java:137) at org.jberet.runtime.runner.JobExecutionRunner.run(JobExecutionRunner.java:55) at org.wildfly.extension.batch.jberet.deployment.BatchEnvironmentService$WildFlyBatchEnvironment$1.run(BatchEnvironmentService.java:180) at org.wildfly.extension.requestcontroller.RequestController$QueuedTask$1.run(RequestController.java:494) at org.jberet.spi.JobExecutor$2.run(JobExecutor.java:149) at org.jberet.spi.JobExecutor$1.run(JobExecutor.java:99) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang. Thread .run( Thread .java:748) at org.jboss.threads.JBossThread.run(JBossThread.java:485) Caused by: java.lang.IllegalArgumentException: WFLYWELD0049: Error injecting resource into CDI managed bean. Can't find a resource named java:app/AppName defined on private java.lang. String org.jboss.as.quickstarts.batch.job.listener.JobListener.applicationName at org.jboss.as.weld.services.bootstrap.WeldResourceInjectionServices.resolveResource(WeldResourceInjectionServices.java:239) at org.jboss.as.weld.services.bootstrap.WeldResourceInjectionServices$1.createResource(WeldResourceInjectionServices.java:183) at org.jboss.weld.injection.AbstractResourceInjection.getResourceReference(AbstractResourceInjection.java:49) at org.jboss.weld.injection.AbstractResourceInjection.injectResourceReference(AbstractResourceInjection.java:63) at org.jboss.weld.util.Beans.injectEEFields(Beans.java:309) at org.jboss.weld.injection.producer.ResourceInjector$1.proceed(ResourceInjector.java:68) at org.jboss.weld.injection.InjectionContextImpl.run(InjectionContextImpl.java:48) at org.jboss.weld.injection.producer.ResourceInjector.inject(ResourceInjector.java:71) at org.jboss.weld.injection.producer.BasicInjectionTarget.inject(BasicInjectionTarget.java:117) at org.jboss.weld.bean.ManagedBean.create(ManagedBean.java:159) at org.jboss.weld.contexts.unbound.DependentContextImpl.get(DependentContextImpl.java:70) at org.jboss.weld.bean.ContextualInstanceStrategy$DefaultContextualInstanceStrategy.get(ContextualInstanceStrategy.java:100) at org.jboss.weld.bean.ContextualInstance.get(ContextualInstance.java:50) at org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:700) at org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:723) at org.wildfly.extension.batch.jberet.deployment.ArtifactFactoryService.create(ArtifactFactoryService.java:89) at org.jberet.creation.ArtifactFactoryWrapper.create(ArtifactFactoryWrapper.java:44) at org.jberet.runtime.context.JobContextImpl.createArtifact(JobContextImpl.java:197) ... 10 more Caused by: javax.naming.NameNotFoundException: java:app/AppName at org.jboss.as.naming.InitialContext$DefaultInitialContext.findContext(InitialContext.java:191) at org.jboss.as.naming.InitialContext$DefaultInitialContext.lookup(InitialContext.java:235) at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:193) at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:189) at javax.naming.InitialContext.lookup(InitialContext.java:417) at javax.naming.InitialContext.lookup(InitialContext.java:417) at org.jboss.as.weld.services.bootstrap.WeldResourceInjectionServices.resolveResource(WeldResourceInjectionServices.java:237) ... 27 more

      Description

      With a JEE aplication in a WAR package, when starting a functionality, as a Batch Job, via CLI, CDI injection and JNDI lookup fail to find resources 'java:app/AppName' and 'java:module/ModuleName'.

      For example, a job listener or other job artifact with the following code

      @Resource(lookup="java:app/AppName")
      private String applicationName;

      or

      private String applicationName;
      
      @PostConstruct
      protected void initialize() throws NamingException {
          applicationName = InitialContext.doLookup("java:app/AppName");
      }

      when the batch job is started from JBoss CLI, the following error will be logged:

      javax.naming.NameNotFoundException: java:app/AppName
      

        Gliffy Diagrams

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  Unassigned
                  Reporter:
                  jose.tepedino José Fernando Tepedino Martins
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  6 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved: