【问题标题】:External Configuration of Spring boot and quartz.properties in apache camelapache camel中Spring boot和quartz.properties的外部配置
【发布时间】:2017-05-04 13:25:59
【问题描述】:

我在 Spring Boot 中使用 Apache camel 作为中间层来实现我的代码,并且在我使用quartz2 组件设置camel 中的路由时,我想使用外部quartz.properties 文件来覆盖默认的quartz.properties 文件。有人可以吗请帮我解决这个问题。 我尝试使用 CommandLineRunner 来实现,但出现如下异常 org.springframework.beans.factory.BeanCreationException:创建名为“schedulerApplication”的bean时出错:注入自动装配的依赖项失败;嵌套异常是 java.lang.IllegalArgumentException:无法解析值“${org.quartz.scheduler.instanceName}”中的占位符“org.quartz.scheduler.instanceName”

【问题讨论】:

    标签: spring spring-boot apache-camel quartz-scheduler


    【解决方案1】:

    如果我理解正确,您一定想将自己的石英属性外部化并尝试在 camel-quartz2 组件中使用它。 在quartz.properties 中创建您的自定义条目,如下所示

    quartz.uri=quartz://group/quartzScheduler?cron=0+05+21+?+*+*
    

    以下是示例路线

    public void configure() throws Exception {
            super.configure();
            String externalService= PropertyParser.getInstance().getStringProperty(Key.Service);
            from(quartzEndpoint("sampleQuartz"))
                    .to(externalService)
                    .process(new Processor() {
                        public void process(Exchange e) throws Exception {
                            log.info("Before storing " + MessageHelper.extractBodyAsString(e.getIn()));
                            MyHelper.writeCLOBPut(e);
                            log.info("After storing " + MessageHelper.extractBodyAsString(e.getIn()));
                        }
                    }).log("Stored in DB");
        }
    

    希望这有帮助

    【讨论】:

    • 感谢balaji的回复,我仍然不清楚你的代码中的“sampleQuartz”是什么,因为它应该是正确的端点。我在我的代码中使用了quartz2组件。
    • 我没有像这样编写 cron 表达式,而是编写了一个配置器方法“quartzEndpoint”,它接受一个名称并从数据库中获取 cron 表达式。用简单的方式你可以这样写 - from("quartz2://myGroup/myTimerName?cron=0+0/5+12-18+?+*+MON-FRI")
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-10-10
    • 2020-03-10
    • 2017-11-26
    • 2018-01-17
    • 2021-01-05
    • 2019-08-17
    • 1970-01-01
    相关资源
    最近更新 更多