WildFly 8.2 中的错误 运行 批处理作业 Java EE 7

Error Running Batch Job in WildFly 8.2 Java EE 7

我正尝试通过 Servlet 运行 批处理作业。当以下语句执行 JobOperator jo = BatchRuntime.getJobOperator(); 时,出现以下错误:

ERROR [io.undertow.request] (default task-8) UT005023: Exception handling request to /BatchProcessing/batchprocessing: java.util.ServiceConfigurationError: javax.batch.operations.JobOperator: Provider org.jberet.operations.JobOperatorImpl could not be instantiated: java.lang.IllegalStateException: JBAS020560: BeanManager service was not added on the deployment. Ensure the deployment has a META-INF/batch.xml file or the META-INF/batch-jobs directory contains batch configuration files.
    at java.util.ServiceLoader.fail(ServiceLoader.java:224) [rt.jar:1.7.0_51]
    at java.util.ServiceLoader.access0(ServiceLoader.java:181) [rt.jar:1.7.0_51]
    at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:377) [rt.jar:1.7.0_51]
    at java.util.ServiceLoader.next(ServiceLoader.java:445) [rt.jar:1.7.0_51]
    at javax.batch.runtime.BatchRuntime.getJobOperator(BatchRuntime.java:57) [jboss-batch-api_1.0_spec-1.0.0.Final.jar:1.0.0.Final]
    at com.tcs.servlets.BatchServlets.doPost(BatchServlets.java:43) [classes:]
    at com.tcs.servlets.BatchServlets.doGet(BatchServlets.java:29) [classes:]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:687) [jboss-servlet-api_3.1_spec-1.0.0.Final.jar:1.0.0.Final]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) [jboss-servlet-api_3.1_spec-1.0.0.Final.jar:1.0.0.Final]
    at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]
    at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:61) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]
    at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]
    at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) [undertow-core-1.1.0.Final.jar:1.1.0.Final]
    at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]
    at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:56) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) [undertow-core-1.1.0.Final.jar:1.1.0.Final]
    at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:45) [undertow-core-1.1.0.Final.jar:1.1.0.Final]
    at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:63) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]
    at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:58) [undertow-core-1.1.0.Final.jar:1.1.0.Final]
    at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:70) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]
    at io.undertow.security.handlers.SecurityInitialHandler.handleRequest(SecurityInitialHandler.java:76) [undertow-core-1.1.0.Final.jar:1.1.0.Final]
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) [undertow-core-1.1.0.Final.jar:1.1.0.Final]
    at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) [undertow-core-1.1.0.Final.jar:1.1.0.Final]
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) [undertow-core-1.1.0.Final.jar:1.1.0.Final]
    at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:261) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]
    at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:247) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]
    at io.undertow.servlet.handlers.ServletInitialHandler.access[=12=]0(ServletInitialHandler.java:76) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]
    at io.undertow.servlet.handlers.ServletInitialHandler.handleRequest(ServletInitialHandler.java:166) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]
    at io.undertow.server.Connectors.executeRootHandler(Connectors.java:197) [undertow-core-1.1.0.Final.jar:1.1.0.Final]
    at io.undertow.server.HttpServerExchange.run(HttpServerExchange.java:759) [undertow-core-1.1.0.Final.jar:1.1.0.Final]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_51]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_51]
    at java.lang.Thread.run(Thread.java:744) [rt.jar:1.7.0_51]
Caused by: java.lang.IllegalStateException: JBAS020560: BeanManager service was not added on the deployment. Ensure the deployment has a META-INF/batch.xml file or the META-INF/batch-jobs directory contains batch configuration files.
    at org.wildfly.jberet.services.BatchEnvironmentService$WildFlyBatchEnvironment.getArtifactFactory(BatchEnvironmentService.java:131) [wildfly-jberet-8.2.0.Final.jar:8.2.0.Final]
    at org.wildfly.jberet.DelegatingBatchEnvironment.getArtifactFactory(DelegatingBatchEnvironment.java:51) [wildfly-jberet-8.2.0.Final.jar:8.2.0.Final]
    at org.jberet.operations.JobOperatorImpl.<init>(JobOperatorImpl.java:69) [jberet-core-1.0.2.Final.jar:1.0.2.Final]
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) [rt.jar:1.7.0_51]
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) [rt.jar:1.7.0_51]
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) [rt.jar:1.7.0_51]
    at java.lang.reflect.Constructor.newInstance(Constructor.java:526) [rt.jar:1.7.0_51]
    at java.lang.Class.newInstance(Class.java:374) [rt.jar:1.7.0_51]
    at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:373) [rt.jar:1.7.0_51]
    ... 32 more

我已将 job.xml 文件放在“WebContent/META-INF/batch-jobs/”文件夹中。 不知道配置有什么问题。我还在 META-INF 文件夹中添加了 batch.xml 文件,但它仍然给我同样的错误。感谢任何帮助。

要解决此问题,需要执行多个步骤。首先需要在动态 Web 项目中启用 JPA。要在您的项目中启用 JPA,请按照以下说明操作:

  1. 右键单击项目并转到属性。
  2. 转到项目方面。
  3. 单击 JPA 复选框。
  4. 单击“确定”。

Eclipse 将再次构建项目并在项目的src 文件夹中创建META-INF 文件夹。其次,需要在此(src/META-INF)文件夹中创建批处理作业文件夹。第三,需要在 WEB-INF 文件夹中创建 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>

构建并重新部署项目。这些错误将消失。