我有一个启动bean。我想在此开始一些小程序工作。
我使用@Nemed
和@Dependent
对批处理类进行了注释。我想在batchlet中使用一些像ReportService这样的ejb,但是注入不起作用。如何将EJB注入我的小程序?
我在wildfly 11.0.0.Alpha1上部署了以下示例,并在服务对象中获得了空引用。
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;
}
}
测试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 {
.....
}
答案 0 :(得分:0)
您没有在类ReportService上使用@Local anantotaion实现任何接口。
尝试一下:
@Stateless
@LocalBean
public class ReportService {
.....
}
或
@Stateless
public class ReportService implements ReportServiceLocal{
.....
}
@Local
public interface ReportServiceLocal {
.....
}
请选中此link