Skip to main content

[jsr352-public] Re: Injection into a Batchlet

  • From: Scott Kurz < >
  • To:
  • Subject: [jsr352-public] Re: Injection into a Batchlet
  • Date: Mon, 6 May 2013 08:44:24 -0400

Vijai,

By "inject something else" I assume you mean via CDI.

To inject via CDI you need to load the artifact itself via CDI.

To do this you have to annotate your batch artifact with @Named then refer to the bean name in JSL.


For other standard EE technologies like JPA, note you should be able to inject EntityManager "normally" via  @PersistenceContext
if you wanted to go that route.

Hope that helps,

------------------------------------------------------------------------------

E.g.:

Java:

import javax.inject.Named;

@Named
public class FCUBSBatchlet


JSL:

<job id="sampleAnalysisJob" xmlns="http://xmlns.jcp.org/xml/ns/javaee"
   ...
<step id="...
<batchlet ref="fCUBSatchlet"> <!-- Default bean name -->

------

Or:

@Named("FCUBSBatchlet")
public class FCUBSBatchlet


JSL:

<job id="sampleAnalysisJob" xmlns="http://xmlns.jcp.org/xml/ns/javaee"
   ...
<step id="...
<batchlet ref="FCUBSatchlet">
------------------------------------------------------
Scott Kurz
WebSphere Batch / Compute Grid Development
T/L 295-5649;
External Phone 845-435-5649

--------------------------------------------------------


Inactive hide details for Vijay Nair ---05/04/2013 02:37:51 PM---Hi Mahesh, ****************Vijay Nair ---05/04/2013 02:37:51 PM---Hi Mahesh, ****************

From: Vijay Nair < >
To: ,
Date: 05/04/2013 02:37 PM
Subject: [jsr352-public] Re: Injection into a Batchlet





Hi Mahesh,

****************

Batchlet code
****************


package com.ofss;

import javax.batch.api.AbstractBatchlet;
import javax.batch.api.BatchProperty;
import javax.batch.runtime.context.JobContext;
import javax.inject.Inject;
import javax.persistence.EntityManager;

public class FCUBSBatchlet extends AbstractBatchlet{
   
    @Inject
    @UBS
    EntityManager em;
   
    @Inject
    JobContext jobCtx;
   
    @Inject
    @BatchProperty(name="procedureName")
    private String procedureName;
   
    @Inject
    @BatchProperty(name="procedureMethod")
    private String procedureMethod;
    @Override
    public String process(){
        try{
            System.out.println("Entity Manager is*****"+em); //Returns null
            return "SUCCESS";
        }catch(Exception ex){
            ex.printStackTrace();
            return "FAILURE";
        }
    }
}

**********

Job XML
**********

<job id="FCEODJOB-1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" version="1.0">
    <step id="step-1">
        <batchlet ref="ubsBatchlet">
            <properties>
                <property name="procedureName" value="XXXXX"/>
                <property name="procedureMethod" value="YYYYYY"/>
            </properties>
        </batchlet>
    </step>
</job>

Thanks...Vijay

GIF image



[jsr352-public] Injection into a Batchlet

fusionvj 05/04/2013

[jsr352-public] Re: Injection into a Batchlet

05/04/2013

[jsr352-public] Re: Injection into a Batchlet

Vijay Nair 05/04/2013

[jsr352-public] Re: Injection into a Batchlet

Scott Kurz 05/06/2013

[jsr352-public] Re: Injection into a Batchlet

Scott Kurz 05/06/2013

[jsr352-public] Re: Injection into a Batchlet

Vijay Nair 05/06/2013

[jsr352-public] Re: Injection into a Batchlet

Scott Kurz 05/06/2013

[jsr352-public] Re: Injection into a Batchlet

Vijay Nair 05/06/2013

[jsr352-public] Re: Injection into a Batchlet

Scott Kurz 05/06/2013

[jsr352-public] Re: Injection into a Batchlet

Vijay Nair 05/06/2013

[jsr352-public] Re: Injection into a Batchlet

Scott Kurz 05/06/2013

[jsr352-public] Re: Injection into a Batchlet

Ricardo Cervera-Navarro 05/06/2013

[jsr352-public] Re: Injection into a Batchlet

Vijay Nair 05/07/2013
 
 
Close
loading
Please Confirm
Close