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 09:24:24 -0400

Vijay,

What value did you use for @Named and your JSL 'ref' attribute?

------------------------------------------------------
Scott Kurz
WebSphere Batch / Compute Grid Development
T/L 295-5649;
External Phone 845-435-5649

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


Inactive hide details for Vijay Nair ---05/06/2013 09:21:31 AM---Thanks for your email Scott, I did try this by loading the BatVijay Nair ---05/06/2013 09:21:31 AM---Thanks for your email Scott, I did try this by loading the Batchlet via the @Named annotation instea

From: Vijay Nair < >
To: ,
Date: 05/06/2013 09:21 AM
Subject: [jsr352-public] Re: Injection into a Batchlet





Thanks for your email Scott,

I did try this by loading the Batchlet via the @Named annotation instead of using batch.xml. It gives a ClassNotFound error

Thanks...Vijay


On Mon, May 6, 2013 at 6:27 PM, Scott Kurz < " target="_blank"> > wrote:
    One more comment Vijai...

    I realize this plus my earlier response could be confusing... though my sample could should still work for you all the same.


    I was trying to answer the question of how to inject the EntityManager via CDI (as you'd done in your last sample code) and remain neutral about why your JPA injection (which you'd done originally) didn't work.. since I didn't know the answer.


    However, an earlier email from Mahesh popped into my head....   It seems in Glassfish that @
    PersistenceContext injection will only work if you also use CDI-based loading.

    So whereas from the pure batch perspective, we still support injection via @BatchProperty in non-CDI (batch.xml-based) artifact loading, it seems that ... in Glassfish at least, CDI is required to get the full API set you might expect.


    Hope that helps,


    ------------------------------------------------------
    Scott Kurz
    WebSphere Batch / Compute Grid Development
    T/L 295-5649;
    External Phone
    845-435-5649
    " target="_blank">
    --------------------------------------------------------



    Inactive hide details for Scott Kurz---05/06/2013 08:44:59 AM---Vijai, By "inject something else" I assume you mean via CDI.Scott Kurz---05/06/2013 08:44:59 AM---Vijai, By "inject something else" I assume you mean via CDI.

    From:
    Scott Kurz/Poughkeepsie/IBM@IBMUS
    To:
    " target="_blank"> ,
    Date:
    05/06/2013 08:44 AM

    Subject:
    [jsr352-public] Re: Injection into a Batchlet





    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
    " target="_blank">
    --------------------------------------------------------


    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 < " target="_blank"> >
    To:
    " target="_blank"> ,
    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