Reputation: 1611
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
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