我想使用 EJB 填充列表的 batchlet 有问题。
当我启动项目时,glassfish 会标记一个错误:
捕获异常执行步骤:com.ibm.jbatch.container.exception.BatchContainerRuntimeException: java.lang.NullPointerException
Glassfish 版本是 4.1.1
我的批处理代码是:
@Named
public class getPingStatusBatchlet extends AbstractBatchlet {
private static GetPingStatus gps = new GetPingStatus();
private List<Node> nodes = null;
@EJB
private NodeFacade nodeEJB;
@Override
public String process() throws NamingException {
nodes = nodeEJB.findAll();
for (Node item : nodes) {
gps.getPingStatus(item.getIpv4());
}
return "COMPLETED";
}
@Override
public void stop() throws Exception {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}
我尝试在调试中运行应用程序并检查 nodeEJB,它始终保持空值。
您知道如何将我的 EJB 用于我的 batchlet 吗?
谢谢你的帮助
厄施
编辑:
NodeFacade 代码:
@Stateless
public class NodeFacade extends AbstractFacade<Node> {
@PersistenceContext(unitName = "powwoPU")
private EntityManager em;
@Override
protected EntityManager getEntityManager() {
return em;
}
public NodeFacade() {
super(Node.class);
}
}
豆类.xml:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd"/>
getNetworkStatusBatch.xml:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<job version="1.0" id="getNetworkStatusBatch" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://www.oracle.com/webfolder/technetwork/jsc/xml/ns/javaee/jobXML_1_0.xsd" xmlns="http://xmlns.jcp.org/xml/ns/javaee" >
<step id="getNetworkStatusBatchlet">
<batchlet ref="com.powwo.app.batchlet.getPingStatusBatchlet"/>
</step>
</job>
myBackgroundJobManager.java:
@Singleton
@Startup
public class BackgroundJobManager {
@Schedule(minute = "*", hour = "*", second = "*/10", persistent = false)
public void myBackgroundJobManager() {
BatchRuntime.getJobOperator().start("getNetworkStatusBatch", null);
}
}