尝试运行批处理时出现此错误:
16:05:35,807警告[org.jberet](批处理线程-1)JBERET000001:无法运行批处理org.jberet.job.model.RefArtifact@2dea3d8a:java.lang.IllegalStateException:JBERET000600:无法创建带有以下内容的工件参考名称MyBatchlet。确保存在CDI beans.xml,并且正确配置了batch.xml(如果有)。在org.jberet.runtime.context.JobContextImpl.createArtifact(JobContextImpl.java:185)在org.jberet.runtime.runner.AbstractRunner.createArtifact(AbstractRunner.java:156)在org.jberet.runtime.runner.BatchletRunner.run(BatchletRunner.java:66)在org.jberet.runtime.runner.StepExecutionRunner.runBatchletOrChunk(StepExecutionRunner.java:229)在org.jberet.runtime.runner.StepExecutionRunner.run(StepExecutionRunner.java:147)在org.jberet.runtime.runner.CompositeExecutionRunner.runStep(CompositeExecutionRunner.java:164)在org.jberet.runtime.runner.CompositeExecutionRunner.runFromHeadOrRestartPoint(CompositeExecutionRunner.java:88)在org.jberet.runtime.runner.JobExecutionRunner.run(JobExecutionRunner.java:60)在org.wildfly.extension.batch.jberet.impl.BatchEnvironmentService $ WildFlyBatchEnvironment $ 1.run(BatchEnvironmentService.java:243)在org.wildfly.extension.requestcontroller.RequestController $ QueuedTask $ 1.run(RequestController.java:497)在org.jberet.spi.JobExecutor $ 3.run(JobExecutor.java:161)在org.jberet.spi.JobExecutor $ 1.run(JobExecutor.java:99)在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)在java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:624)在java.lang.Thread.run(Thread.java:748)在org.jboss.threads.JBossThread.run(JBossThread.java:320)原因:java.lang.IllegalStateException:JBERET000600:无法创建参考名称为MyBatchlet的工件。确保存在CDI beans.xml,并且正确配置了batch.xml(如果有)。在org.jberet.creation.ArtifactFactoryWrapper.getClassFromBatchXmlOrClassLoader(ArtifactFactoryWrapper.java:65)在org.jberet.creation.ArtifactFactoryWrapper.create(ArtifactFactoryWrapper.java:41)在org.jberet.runtime.context.JobContextImpl.createArtifact(JobContextImpl.java:183)...另外15个原因:java.lang.ClassNotFoundException:[服务模块加载器中的[module“ deployment.idkwebapp.war:main”中的] MyBatchlet。在org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:198)在org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:363)在org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:351)在org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:93)在org.jberet.creation.ArtifactFactoryWrapper.getClassFromBatchXmlOrClassLoader(ArtifactFactoryWrapper.java:63)... 17更多
我创建了beans.xml,但仍然无法正常工作...
<?xml version="1.0" encoding="UTF-8"?>
<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">
</beans>
这里是批处理:
package br.com.idk;
import javax.batch.runtime.context.JobContext;
import javax.batch.runtime.context.StepContext;
import javax.inject.Inject;
public class MyBatchlet {
@Inject JobContext jobContext;
@Inject StepContext stepContext;
public String process() throws Exception {
long executionId = jobContext.getExecutionId();
System.out.println("I'm a cool batchlet!!!!!!!!!!!!!!!");
return null;
}
public void stop() throws Exception {
// TODO Auto-generated method stub
}
}
我在这里叫它:
package br.com.idk;
import java.util.Properties;
import javax.batch.operations.JobOperator;
import javax.batch.runtime.BatchRuntime;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
@Path("/hello")
public class Resource {
@GET
@Path("testBatch")
public Long testBatch() {
JobOperator jobOperator = BatchRuntime.getJobOperator();
Properties props = new Properties();
props.setProperty("name", "Dude");
return jobOperator.start("simple-batchlet-job", props);
}
}
这是工作的XML:
<?xml version="1.0" encoding="UTF-8"?>
<job id="simple-batchlet-job" xmlns="http://xmlns.jcp.org/xml/ns/javaee">
<step id="myBatchlet">
<batchlet ref="MyBatchlet"/>
</step>
</job>
像这样用bean-discovery-mode =“ all”更改您的beans.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
bean-discovery-mode="all">
</beans>