gpt4 book ai didi

java - 当尝试启动应用程序时,spring-quartz 不会启动并显示错误消息?

转载 作者:行者123 更新时间:2023-12-02 09:14:33 24 4
gpt4 key购买 nike

websphere8.5.5.13上部署了spring应用

我尝试使用 spring-quartz 通过 cron 来安排我的作业,但它们开始时出现错误我的 quartz 配置类

  @Configuration
@Import(PersistenceConfig.class)
@PropertySource(value = {"classpath:application.properties"})
@EnableScheduling
public class ExportConfig {
private Logger logger = Logger.getLogger(getClass());
@Autowired
private DataSource dataSource;
@Autowired
private EntityManagerFactory entityManagerFactory;
@Getter
@Autowired
private MyService service;

private final String QRTZ_TRIGGER = "My_TRIGGER";
private final String QRTZ_GROUP = "My_GROUP";
private final String QRTZ_JOB = "MyJOB";
private final String TIME = "0 0-59 0-23 * * ?"; /* каждый час, каждые 0,15,30,45 минут */

@Bean
@DependsOn(value = {"entityManagerFactory", "dataSource"})
public JobDetail cronJobMy() {
JobKey jobKey = new JobKey(QRTZ_JOB, QRTZ_GROUP);
return JobBuilder
.newJob(MyJob.class)
.storeDurably(true)
.requestRecovery(true)
.withIdentity(jobKey).build();
}

@Bean
@DependsOn(value = {"entityManagerFactory", "dataSource"})
public Trigger cronTriggerMy() {
TriggerKey triggerKey = new TriggerKey(QRTZ_TRIGGER, QRTZ_GROUP);
return TriggerBuilder
.newTrigger()
.withIdentity(triggerKey)
.withSchedule(createSchedule(TIME)).build();
}

@Bean
@DependsOn(value = {"entityManagerFactory", "dataSource"})
public Scheduler cronSchedulerMy(JobDetail cronJobMy, Trigger cronTriggerMy) throws SchedulerException {
StdSchedulerFactory factory = new StdSchedulerFactory("quartzStandalone.properties");
Scheduler scheduler = factory.getScheduler();
boolean triggerExist = scheduler.checkExists(cronTriggerMy.getKey());
boolean jobExist = scheduler.checkExists(cronJobMy.getKey());

if (triggerExist || jobExist) {
scheduler.deleteJob(new JobKey(QRTZ_JOB, QRTZ_GROUP));
}

scheduler.start();
scheduler.getContext().put("SERVICE", service);
scheduler.scheduleJob(cronJobMy, cronTriggerMy);
return scheduler;
}

private static ScheduleBuilder createSchedule(String cronExpression) {
CronScheduleBuilder builder = CronScheduleBuilder.cronSchedule(cronExpression);
return builder;
}
}

工作看起来像这样:

@DisallowConcurrentExecution
@PersistJobDataAfterExecution
public class ExportJob implements Job {
private static final String MESSAGE = "===================================EXPORT QUARTZ TACT===================================";
private Logger logger = Logger.getLogger(getClass());

@Override
public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
logger.log(Level.INFO, MESSAGE);
try {
ApplicationContext springContext =
WebApplicationContextUtils.getWebApplicationContext(ContextLoaderListener.getCurrentWebApplicationContext().getServletContext());
Object bean = springContext.getBean("exportService");
if (bean != null) {
ExportService exportService = (ExportService) bean;
exportService.export();
}
} catch (Exception e) {
e.printStackTrace();
logger.log(Level.ERROR, "EXPORT_SERVICE_BY_QUARTZ Failed..");
logger.log(Level.ERROR, Arrays.toString(e.getStackTrace()));
}
}
}

属性文件

#============================================================================
# Configure Main Scheduler Properties
# Configure Main Scheduler Properties
#============================================================================

org.quartz.scheduler.instanceName = MYAPPStandaloneScheduler
org.quartz.scheduler.instanceId = AUTO
#============================================================================
# Configure ThreadPool
#============================================================================

org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool
org.quartz.threadPool.threadCount = 1
org.quartz.threadPool.makeThreadsDaemons = true
#============================================================================
# Configure JobStore
#============================================================================

org.quartz.jobStore.misfireThreshold = 60000

org.quartz.jobStore.class = org.quartz.impl.jdbcjobstore.JobStoreTX
org.quartz.jobStore.driverDelegateClass = org.quartz.impl.jdbcjobstore.oracle.OracleDelegate
org.quartz.jobStore.useProperties = false
org.quartz.jobStore.dataSource = MYAPP
org.quartz.jobStore.tablePrefix = QRTZ_
org.quartz.jobStore.isClustered = false
org.quartz.jobStore.clusterCheckinInterval = 20000
org.quartz.dataSource.MYAPP.jndiURL = java:comp/env/jdbc/MYAPP

我的pom.xml

 <!-- Quartz for schedule -->
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz</artifactId>
<version>2.3.2</version>
</dependency>
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz-oracle</artifactId>
<version>1.8.5</version>
</dependency>

但是,当尝试启动我的应用程序时,出现错误消息

'MYAPPStandaloneScheduler' with instanceId 'NON_CLUSTERED' Scheduler class: 'org.quartz.core.QuartzScheduler' - running locally. NOT STARTED. Currently in standby mode. Number of jobs executed: 0
Using thread pool 'org.quartz.simpl.SimpleThreadPool' - with 1 threads. Using job-store 'org.quartz.impl.jdbcjobstore.JobStoreTX' - which supports persistence. and is not clustered.

[11/29/19 9:05:21:513 MSK] 00000109 SystemOut O [2019-11-29 09:05:21.513] INFO org.quartz.impl.StdSchedulerFactory Quartz scheduler 'MYAPPStandaloneScheduler' initialized from the specified file : 'quartzStandalone.properties' from the class resource path. [11/29/19 9:05:21:521 MSK] 00000109 SystemOut O [2019-11-29 09:05:21.521] WARN rt.AnnotationConfigWebApplicationContext Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cronSchedulerExport' defined in class path resource [quartz/ExportConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.quartz.Scheduler]: Factory method 'cronSchedulerExport' threw exception; nested exception is org.quartz.impl.jdbcjobstore.NoSuchDelegateException: Couldn't create delegate: org.quartz.impl.jdbcjobstore.oracle.OracleDelegate [See nested exception: pringframework.web.context.ContextLoader Context initialization failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cronSchedulerExport' defined in class path resource [quartz/ExportConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.quartz.Scheduler]: Factory method 'cronSchedulerExport' threw exception; nested exception is org.quartz.impl.jdbcjobstore.NoSuchDelegateException: Couldn't create delegate: org.quartz.impl.jdbcjobstore.oracle.OracleDelegate [See nested exception: java.lang.InstantiationException: org.quartz.impl.jdbcjobstore.oracle.OracleDelegate] at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599) 75) at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:905) at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1892) Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.quartz.Scheduler]: Factory method 'cronSchedulerExport' threw exception; nested exception is org.quartz.impl.jdbcjobstore.NoSuchDelegateException: Couldn't create delegate: org.quartz.impl.jdbcjobstore.oracle.OracleDelegate [See nested exception: java.lang.InstantiationException: org.quartz.impl.jdbcjobstore.oracle.OracleDelegate] at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189) at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588) ... 76 more Caused by: org.quartz.impl.jdbcjobstore.NoSuchDelegateException: Couldn't create delegate: org.quartz.impl.jdbcjobstore.oracle.OracleDelegate [See nested exception: java.lang.InstantiationException: org.quartz.impl.jdbcjobstore.oracle.OracleDelegate] at org.quartz.impl.jdbcjobstore.JobStoreSupport.getDelegate(JobStoreSupport.java:3218) ... 77 more Caused by: java.lang.InstantiationException: org.quartz.impl.jdbcjobstore.oracle.OracleDelegate at java.lang.J9VMInternals.newInstanceImpl(Native Method) at java.lang.Class.newInstance(Class.java:1762) at org.quartz.impl.jdbcjobstore.JobStoreSupport.getDelegate(JobStoreSupport.java:3213) ... 96 more [11/29/19 9:05:21:537 MSK] 00000109 webapp E com.ibm.ws.webcontainer.webapp.WebApp notifyServletContextCreated SRVE0283E: Exception caught while initializing context: {0} org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cronSchedulerExport' defined in class path resource [quartz/ExportConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.quartz.Scheduler]: Factory method 'cronSchedulerExport' threw exception; nested exception is org.quartz.impl.jdbcjobstore.NoSuchDelegateException: Couldn't create delegate: org.quartz.impl.jdbcjobstore.oracle.OracleDelegate [See nested exception: java.lang.InstantiationException: org.quartz.impl.jdbcjobstore.oracle.OracleDelegate] at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599) at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:813) at com.ibm.ws.management.AdminServiceImpl$1.run(AdminServiceImpl.java:1350) at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:905) at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1892) Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.quartz.Scheduler]: Factory method 'cronSchedulerExport' threw exception; nested exception is org.quartz.impl.jdbcjobstore.NoSuchDelegateException: Couldn't create delegate: org.quartz.impl.jdbcjobstore.oracle.OracleDelegate [See nested exception: java.lang.InstantiationException: org.quartz.impl.jdbcjobstore.oracle.OracleDelegate] at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189) at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588) ... 76 more Caused by: org.quartz.impl.jdbcjobstore.NoSuchDelegateException: Couldn't create delegate: org.quartz.impl.jdbcjobstore.oracle.OracleDelegate [See nested exception: java.lang.InstantiationException: org.quartz.impl.jdbcjobstore.oracle.OracleDelegate] at org.quartz.impl.jdbcjobstore.JobStoreSupport.getDelegate(JobStoreSupport.java:3218) at org.quartz.impl.jdbcjobstore.JobStoreSupport.checkExists(JobStoreSupport.java:1988) at org.quartz.impl.jdbcjobstore.JobStoreSupport$23.execute(JobStoreSupport.java:1981) at org.quartz.impl.jdbcjobstore.JobStoreSupport.executeInNonManagedTXLock(JobStoreSupport.java:3864) at org.quartz.impl.jdbcjobstore.JobStoreTX.executeInLock(JobStoreTX.java:93) at org.quartz.impl.jdbcjobstore.JobStoreSupport.executeWithoutLock(JobStoreSupport.java:3800) at org.quartz.impl.jdbcjobstore.JobStoreSupport.

org.quartz.impl.jdbcjobstore.NoSuchDelegateException: Couldn't create delegate:

作业的状态保存在_QRTZ - 数据库 Oracle11g 中的表中

最佳答案

为什么不使用 Spring quartz 启动器?您可以使用 spring 数据源而不是专用数据源:

spring:
datasource:
driver-class-name: org.postgresql.Driver
url: jdbc:postgresql://127.0.0.1:5432/postgres
username: postgres
password: password
quartz:
scheduler-name: quartzSchedulernot work anymore
jobStore: jdbc
startup-delay: PT10S
wait-for-jobs-to-complete-on-shutdown: true
properties:
org.quartz.scheduler.instanceId: AUTO
org.quartz.scheduler.jmx.export: true
org.quartz.threadPool.threadCount: 15
org.quartz.threadPool.threadPriority: 5
org.quartz.threadPool.class: org.quartz.simpl.SimpleThreadPool
org.quartz.threadPool.threadsInheritContextClassLoaderOfInitializingThread: true
org.quartz.jobStore.driverDelegateClass: org.quartz.impl.jdbcjobstore.PostgreSQLDelegate
org.quartz.jobStore.tablePrefix: QRTZ_
org.quartz.jobStore.isClustered: true
org.quartz.jobStore.clusterCheckinInterval: 1000

您还必须删除您的调度程序创建并让 spring 为您完成。

关于java - 当尝试启动应用程序时,spring-quartz 不会启动并显示错误消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59103963/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com