mohammad_1m2
mohammad_1m2

Reputation: 1611

Java batch - inject ejb to batchlet

I have a startup bean. I want to start some batchlet job in this. I annotated the batchlet class by use @Nemed and @Dependent . I want to use some ejb like ReportService in batchlet but Injection not work. How can I inject EJB to my batchlet? I deployed below example on wildfly 11.0.0.Alpha1 and got empty reference in service object.

BatchletTest:

@Dependent
@Named("BatchletTest")
public class BatchletTest extends AbstractBatchlet{


    public BatchletTest() {
    }

    @Inject
    ReportService service;

    @Override
    public String process() throws Exception {
        System.out.println(service);
        return null;
    }
}

test-job.xml

 <job id="test-job" xmlns="http://xmlns.jcp.org/xml/ns/javaee" version="1.0">
        <step id="testStep">
            <batchlet ref="com.test.BatchletTest" />
        </step>
    </job>

StartupBean:

@Singleton
@Startup
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public class StartupBean {

    private Logger logger = LoggerFactory.getLogger(StartupBean.class);

    @PostConstruct
    private void startup() throws Exception {
            long executionId = BatchRuntime.getJobOperator().start("test-job", new Properties());
            System.out.println("myJob started, execution ID = " + executionId);

    }

}

ReportService:

@Stateless
public class ReportService {
.....
}

Upvotes: 1

Views: 680

Answers (1)

Mat&#237;as Galli
Mat&#237;as Galli

Reputation: 101

You are no implementing any interface with @Local anntotaion on your class ReportService.

Try this:

@Stateless
@LocalBean
public class ReportService {
.....
}

or

@Stateless
public class ReportService implements ReportServiceLocal{
.....
}

@Local
public interface ReportServiceLocal {
.....
}

Please check this link

Upvotes: 0

Related Questions