1

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 {
.....
}
mohammad_1m2
  • 1,571
  • 5
  • 19
  • 38
  • Which application server and which version? Any warning and errors in server log? There should be some CDI injection related warning/erorrs in log. One possibility is that you're using the FQCN as the bean ref in job xml, which may bypass the CDI loading, which makes the {{service}} injection field out of the reach of CDI. – cheng Jan 19 '18 at 21:49
  • I deployed in on wildfly 11.0.0.Alpha1. There was no error in logs. – mohammad_1m2 Jan 19 '18 at 22:04
  • 1
    Try using the CDI bean name as the batch artifact ref so that CDI can handle the ejb injection into your batchlet class. – cheng Jan 19 '18 at 23:06

1 Answers1

0

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