我正在尝试使用JBERET实现在Java SE模式下运行JSR352 java批处理程序。我可以看到我的main()方法被执行了。在这个main()方法中,我得到了一个作业操作员并开始工作。
public static void main(String[] args) {
LoggingConfig logConfiguration = new LoggingConfig();
logger.info("Begining Batch with JBeret approach");
JobOperator jo = BatchRuntime.getJobOperator();
long id = jo.start("PilotJob", null);
logger.info("End of Batch");
}
但是,我没有在我的读者,处理器,作家或听众中看到任何日志声明被打印出来。
我从我的项目src / main / resources / META-INF文件夹中定义并加载了logging.properties。我的main()方法中的日志语句是根据它打印的,但我的读/写器/处理器和监听器中的日志语句根本不打印。
public class LoggingConfig {
public LoggingConfig() {
try {
// Load a properties file from class path that way can't be achieved
// with java.util.logging.config.file
final LogManager logManager = LogManager.getLogManager();
try (final InputStream is = getClass().getResourceAsStream("/META-INF/logging.properties"))
{
logManager.readConfiguration(is);
}
} catch (Exception e) {
System.out.println("Error while reading Log configuration file");
e.printStackTrace();
}
}
}
为什么我的java批处理程序中的日志语句(java日志库)不能打印?
以下是main()方法的日志。我可以清楚地看到作业已经开始,但不确定为什么批处理程序的日志语句没有被打印出来。
INFO: App Begining Batch with JBeret approach - v1.0
INFO: org.jboss.weld.Version WELD-000900: 2.2.15 (Final)
INFO: org.jboss.weld.Bootstrap WELD-ENV-000014: Falling back to Java Reflection for bean-discovery-mode="annotated" discovery. Add org.jboss:jandex to the classpath to speed-up startup.
INFO: org.jboss.weld.Bootstrap WELD-000101: Transactional services not available. Injection of @Inject UserTransaction not available. Transactional observers will be invoked synchronously.
WARN: org.jboss.weld.Interceptor WELD-001700: Interceptor annotation class javax.ejb.PostActivate not found, interception based on it is not enabled
WARN: org.jboss.weld.Interceptor WELD-001700: Interceptor annotation class javax.ejb.PrePassivate not found, interception based on it is not enabled
DEBUG: org.jboss.weld.Bootstrap WELD-000100: Weld initialized. Validating beans
DEBUG: org.jboss.weld.Reflection WELD-000620: interface javax.enterprise.inject.Intercepted is not declared @Target(METHOD, FIELD, PARAMETER, TYPE). Weld will use this annotation, however this may make the application unportable.
DEBUG: org.jboss.weld.Reflection WELD-000620: interface javax.enterprise.inject.Decorated is not declared @Target(METHOD, FIELD, PARAMETER, TYPE). Weld will use this annotation, however this may make the application unportable.
FINE: javax.batch.runtime.BatchRuntime Loaded BatchContainerServiceProvider with className = org.jberet.operations.JobOperatorImpl
TRACE: org.jberet JBERET000022: resume is not implemented for local transactions
DEBUG: org.jberet JBERET000017: Persisted org.jberet.runtime.JobInstanceImpl@6 with id 6
DEBUG: org.jberet JBERET000017: Persisted org.jberet.runtime.JobExecutionImpl@6 with id 6
INFO: App End of Batch
这是一个包含Sysout和Log语句的Listener代码。它们都没有在我的Eclipse控制台中打印出来。
import java.util.logging.Logger;
import javax.batch.api.listener.AbstractJobListener;
public class PilotLibJobListener extends AbstractJobListener {
private final static Logger logger = Logger.getLogger("PilotLibJobListener");
public void beforeJob() {
BatchListenerRecorder.batchListenersCountDownLatch.countDown();
System.out.println("Before Job");
logger.info("MyJobListener.beforeJob");
}
@Override
public void afterJob() {
BatchListenerRecorder.batchListenersCountDownLatch.countDown();
logger.info("MyJobListener.afterJob");
}
}
答案 0 :(得分:0)
要查询作业执行状态,您只需在JobOperator
上调用相应的API,例如public JobExecution getJobExecution(long executionId)
。返回的JobExecution
对象包含最新数据。
对于作业存储库,如果jdbc作业存储库对于您的应用来说太重了,您可以选择内存中的作业存储库。但是使用默认的H2数据库,您可以配置为具有嵌入式或基于文件的H2数据库,而不是客户端 - 服务器模式,以限制资源消耗。
对于日志记录问题,您可以创建JIRA issue或github issue,并附加可重现的测试应用吗?