Конфигурация кварцевого планировщика Spring Boot - PullRequest
0 голосов
/ 21 мая 2019

Я хочу переместить нашу конфигурацию кварцевого планирования в application.yml вместо сохранения отдельного файла quartz.properties.

Наше приложение Spring Boot запускается и выбирает конфигурацию, как и ожидалось, при использовании файла quartz.properties, но не получает конфигурацию из application.yml.

Планировщик bean:

@SpringBootApplication
public class MyApp{
    public static void main(String[] args) {
        SpringApplication.run(MyApp.class, args);
    }

    ...

    @Bean
    public Scheduler scheduler(SomeCustomConfig cfg, RestTemplate restTemplate) throws SchedulerException {
        //StdSchedulerFactory schedulerFactory = new StdSchedulerFactory();
        //schedulerFactory.initialize("quartz.properties");
        Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();
        scheduler.getContext().put("restTemplate", restTemplate);
        scheduler.getContext().put("cfg", cfg);
        return scheduler;
    }

}

Уместно application.yml:

spring:
    application.name: myApp
    quartz:
        properties:
            org:
                quartz:
                    scheduler:
                        instanceId: AUTO
                    threadPool:
                        threadCount: 5
                    plugin:
                        shutdownhook:
                            class: org.quartz.plugins.management.ShutdownHookPlugin
                            cleanShutdown: TRUE
                    jobStore:
                        class: org.quartz.impl.jdbcjobstore.JobStoreTX
                        driverDelegateClass: org.quartz.impl.jdbcjobstore.PostgreSQLDelegate
                        tablePrefix: my_schema.
                        isClustered: true
                        dataSource: myDataSource
                    dataSource:
                        myDataSource:
                            driver: org.postgresql.Driver
                            URL: jdbc:postgresql://localhost/myDataSource
                            user: removed
                            password: removed

Наш quartz.properties был:

org.quartz.scheduler.instanceId = AUTO
org.quartz.plugin.shutdownhook.class = org.quartz.plugins.management.ShutdownHookPlugin
org.quartz.plugin.shutdownhook.cleanShutdown = TRUE
org.quartz.threadPool.threadCount = 5
org.quartz.jobStore.class = org.quartz.impl.jdbcjobstore.JobStoreTX
org.quartz.jobStore.driverDelegateClass = org.quartz.impl.jdbcjobstore.PostgreSQLDelegate
org.quartz.jobStore.tablePrefix = my_schema.
org.quartz.jobStore.isClustered = true
org.quartz.jobStore.dataSource = myDataSource
org.quartz.dataSource.myDataSource.driver = org.postgresql.Driver
org.quartz.dataSource.myDataSource.URL = jdbc:postgresql://localhost/myDataSource
org.quartz.dataSource.myDataSource.user = removed
org.quartz.dataSource.myDataSource.password = removed

Я чувствую, что что-то упустил?

1 Ответ

0 голосов
/ 21 мая 2019

Ваша application.yml конфигурация установлена ​​для spring-boot-starter-quartz, и я думаю, что вы используете org.quartz-scheduler независимо.Поэтому вы должны настроить ваш application.yml примерно так:

spring:
    application.name: myApp
org:
    quartz:
        scheduler:
            instanceId: AUTO
        threadPool:
            threadCount: 5
        plugin:
            shutdownhook:
                class: org.quartz.plugins.management.ShutdownHookPlugin
                cleanShutdown: TRUE
        jobStore:
            class: org.quartz.impl.jdbcjobstore.JobStoreTX
            driverDelegateClass: org.quartz.impl.jdbcjobstore.PostgreSQLDelegate
            tablePrefix: my_schema.
            isClustered: true
            dataSource: myDataSource
        dataSource:
            myDataSource:
                driver: org.postgresql.Driver
                URL: jdbc:postgresql://localhost/myDataSource
                user: removed
                password: removed
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...