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

Java 尝试启动应用程序时,spring quartz不会启动并显示错误消息?,java,spring,quartz,Java,Spring,Quartz,websphere8.5.5.13上部署了spring应用程序 我尝试使用SpringQuartz通过cron来安排我的作业,但它们是以错误开始的 我的石英配置类 @Configuration @Import(PersistenceConfig.class) @PropertySource(value = {"classpath:application.properties"}) @EnableScheduling public class ExportCon

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

我尝试使用SpringQuartz通过cron来安排我的作业,但它们是以错误开始的 我的石英配置类

  @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>

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

为什么不使用spring quartz starter?您可以使用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为您完成

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