当前位置: 首页 > 知识库问答 >
问题:

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

朱承载
2023-03-14

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个答案

双恩
2023-03-14

为什么不使用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为您完成。

 类似资料:
  • 当我尝试运行spring boot应用程序时,我遇到了以下异常: 组织。springframework。豆。工厂BeanCreationException:创建名为“configurationPropertiesBeans”的bean时出错,该bean在类路径资源[org/springframework/cloud/autoconfigure/ConfigurationPropertiesRebi

  • 我正在尝试使用简单的spring启动应用程序。我在ApplicationContext上启动应用程序时遇到问题。 2017-04-26 11:17:31.101警告14528---[main]s.c.a.AnnotationConfigApplicationContext:上下文初始化期间遇到异常-取消刷新尝试:org。springframework。豆。工厂未满足的PendencyExcepti

  • 我想对Spring数据使用ElasticSearch。我使用的是Spring 5、Spring Boot 2和ElasticSearch 7.4。Docker compose: 马文: 存储库: 配置: 和错误时启动应用程序: 引起:java.lang.NoSuchMEDError:org.springframework.http.HttpHeaders.(Lorg/springframe/uti

  • 我在intellij上启动spring boot应用程序时遇到问题,它失败了,并显示以下消息:与目标VM断开连接,地址:'127.0.0.1:49784',传输:'socket' 过程结束,退出代码为255。以前有人遇到过这种情况吗?

  • 我有一份Java申请。 应用程序有一个决定应用程序是否在启动时启动的设置。 目前,我通过在StartUp items文件夹中放置/删除快捷方式实现了这一点。 然而,我想知道是否有更好的方法来处理这种行为。 编辑 是的,是视窗。抱歉之前没有清除。 应用程序有一个UI,用户可以在其中触发操作,并且应用程序在运行时定期在后台运行一些任务。 @Peter,如何使用应用程序中的代码更改注册表?这种方法是否与

  • 当启动部署在Kubernetes中的spring应用程序时,会出现以下logback错误。 2022-04-20 13:47:25.928错误1 --- [ main]o.s.boot.SpringApplication:应用程序运行失败 java.lang.IllegalStateException:检测到注销配置错误:中的错误c.q.l.core.rolling.SizeAndTimeBase