提问者:小点点

Spring-石英在尝试启动应用程序时不启动错误消息?


websphere8.5.5.13上部署了spring应用程序

我尝试使用SpringQuartz通过cron来安排我的作业,但它们以错误my 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>

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

instanceId为“NON\u CLUSTERED”的“MYAPPStandaloneScheduler”调度程序类:“org”。石英果心QuartzScheduler”-在本地运行。未启动。当前处于待机模式。执行的作业数:0
使用线程池组织。石英简单。SimpleThreadPool“-具有1个线程。使用作业存储组织。石英实施。jdbcjobstore。JobStoreTX“-支持持久性。并且不是群集的。

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

作业的状态保存在数据库Oracle11g中的\u QRTZ-表中


共1个答案

匿名用户

为什么不使用Spring石英起动器?您可以使用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为您完成。