最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Camel spring boot starter ignores properties location configuration - Stack Overflow

programmeradmin3浏览0评论

Can not figure out why I am not able to init bean properties by the Camel @PropertyInject during spring boot start. Seems like camelponent.properties.location mentioned in the documentation ignored\doesn't work.

Stacktrace:

.springframework.beans.factory.BeanCreationException: Error creating bean with name 'someBean' defined in file [/home/chandre/IdeaProjects/CamelInAction/properties-spring-boot/build/classes/java/main//example/propertiesspringboot/SomeBean.class]: Error post processing bean: someBean
    at .springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:608) ~[spring-beans-6.2.3.jar:6.2.3]
    at .springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:523) ~[spring-beans-6.2.3.jar:6.2.3]
    at .springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:339) ~[spring-beans-6.2.3.jar:6.2.3]
    at .springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:346) ~[spring-beans-6.2.3.jar:6.2.3]
    at .springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:337) ~[spring-beans-6.2.3.jar:6.2.3]
    at .springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-6.2.3.jar:6.2.3]
    at .springframework.beans.factory.support.DefaultListableBeanFactory.instantiateSingleton(DefaultListableBeanFactory.java:1155) ~[spring-beans-6.2.3.jar:6.2.3]
    at .springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingleton(DefaultListableBeanFactory.java:1121) ~[spring-beans-6.2.3.jar:6.2.3]
    at .springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:1056) ~[spring-beans-6.2.3.jar:6.2.3]
    at .springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:987) ~[spring-context-6.2.3.jar:6.2.3]
    at .springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:627) ~[spring-context-6.2.3.jar:6.2.3]
    at .springframework.boot.SpringApplication.refresh(SpringApplication.java:752) ~[spring-boot-3.4.3.jar:3.4.3]
    at .springframework.boot.SpringApplication.refreshContext(SpringApplication.java:439) ~[spring-boot-3.4.3.jar:3.4.3]
    at .springframework.boot.SpringApplication.run(SpringApplication.java:318) ~[spring-boot-3.4.3.jar:3.4.3]
    at .springframework.boot.SpringApplication.run(SpringApplication.java:1361) ~[spring-boot-3.4.3.jar:3.4.3]
    at .springframework.boot.SpringApplication.run(SpringApplication.java:1350) ~[spring-boot-3.4.3.jar:3.4.3]
    at .example.propertiesspringboot.ExampleApplication.main(ExampleApplication.java:10) ~[main/:na]
Caused by: .springframework.beans.factory.BeanCreationException: Error post processing bean: someBean
    at .apache.camel.spring.spi.CamelBeanPostProcessor.postProcessBeforeInitialization(CamelBeanPostProcessor.java:180) ~[camel-spring-4.10.2.jar:4.10.2]
    at .springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:423) ~[spring-beans-6.2.3.jar:6.2.3]
    at .springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1804) ~[spring-beans-6.2.3.jar:6.2.3]
    at .springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:601) ~[spring-beans-6.2.3.jar:6.2.3]
    ... 16 common frames omitted
Caused by: .apache.camel.RuntimeCamelException: java.lang.IllegalArgumentException: Property with key [foo] not found in properties from text: {{foo}}
    at .apache.camel.RuntimeCamelException.wrapRuntimeCamelException(RuntimeCamelException.java:53) ~[camel-api-4.10.2.jar:4.10.2]
    at .apache.camel.impl.engine.CamelPostProcessorHelper.getInjectionPropertyValue(CamelPostProcessorHelper.java:316) ~[camel-base-engine-4.10.2.jar:4.10.2]
    at .apache.camel.impl.engine.DefaultCamelBeanPostProcessor.setterPropertyInjection(DefaultCamelBeanPostProcessor.java:503) ~[camel-base-engine-4.10.2.jar:4.10.2]
    at .apache.camel.impl.engine.DefaultCamelBeanPostProcessor.setterInjection(DefaultCamelBeanPostProcessor.java:449) ~[camel-base-engine-4.10.2.jar:4.10.2]
    at .apache.camel.impl.engine.DefaultCamelBeanPostProcessor.lambda$injectMethods$6(DefaultCamelBeanPostProcessor.java:360) ~[camel-base-engine-4.10.2.jar:4.10.2]
    at .apache.camel.util.ReflectionHelper.doWithMethods(ReflectionHelper.java:138) ~[camel-util-4.10.2.jar:4.10.2]
    at .apache.camel.impl.engine.DefaultCamelBeanPostProcessor.injectMethods(DefaultCamelBeanPostProcessor.java:355) ~[camel-base-engine-4.10.2.jar:4.10.2]
    at .apache.camel.impl.engine.DefaultCamelBeanPostProcessor.injectFirstPass(DefaultCamelBeanPostProcessor.java:231) ~[camel-base-engine-4.10.2.jar:4.10.2]
    at .apache.camel.impl.engine.DefaultCamelBeanPostProcessor.postProcessBeforeInitialization(DefaultCamelBeanPostProcessor.java:152) ~[camel-base-engine-4.10.2.jar:4.10.2]
    at .apache.camel.spring.spi.CamelBeanPostProcessor.postProcessBeforeInitialization(CamelBeanPostProcessor.java:176) ~[camel-spring-4.10.2.jar:4.10.2]
    ... 19 common frames omitted
Caused by: java.lang.IllegalArgumentException: Property with key [foo] not found in properties from text: {{foo}}
    at .apache.camelponent.properties.DefaultPropertiesParser$ParsingContext.getPropertyValue(DefaultPropertiesParser.java:413) ~[camel-base-4.10.2.jar:4.10.2]
    at .apache.camelponent.properties.DefaultPropertiesParser$ParsingContext.readProperty(DefaultPropertiesParser.java:243) ~[camel-base-4.10.2.jar:4.10.2]
    at .apache.camelponent.properties.DefaultPropertiesParser$ParsingContext.doParseNested(DefaultPropertiesParser.java:174) ~[camel-base-4.10.2.jar:4.10.2]
    at .apache.camelponent.properties.DefaultPropertiesParser$ParsingContext.parse(DefaultPropertiesParser.java:121) ~[camel-base-4.10.2.jar:4.10.2]
    at .apache.camelponent.properties.DefaultPropertiesParser.parseUri(DefaultPropertiesParser.java:73) ~[camel-base-4.10.2.jar:4.10.2]
    at .apache.camelponent.properties.PropertiesComponent.parseUri(PropertiesComponent.java:344) ~[camel-base-4.10.2.jar:4.10.2]
    at .apache.camelponent.properties.PropertiesComponent.parseUri(PropertiesComponent.java:175) ~[camel-base-4.10.2.jar:4.10.2]
    at .apache.camel.impl.engine.DefaultCamelContextExtension.resolvePropertyPlaceholders(DefaultCamelContextExtension.java:351) ~[camel-base-engine-4.10.2.jar:4.10.2]
    at .apache.camel.impl.engine.AbstractCamelContext.resolvePropertyPlaceholders(AbstractCamelContext.java:1656) ~[camel-base-engine-4.10.2.jar:4.10.2]
    at .apache.camel.impl.engine.CamelPostProcessorHelper.getInjectionPropertyValue(CamelPostProcessorHelper.java:293) ~[camel-base-engine-4.10.2.jar:4.10.2]
    ... 27 common frames omitted

application.properties

spring.application.name=example

camel.springboot.main-run-controller=true

camelponent.properties.location=classpath:additional.properties

additional.properties

foo=foo
bar=bar

ExampleApplication.java

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

SomeBean.java

@Component
public class SomeBean {
    String foo;
    String bar;

    @PropertyInject("foo")
    public void setFoo(String foo) {
        this.foo = foo;
    }

    @PropertyInject("bar")
    public void setBar(String bar) {
        this.bar = bar;
    }
}

In case of usage of the .apache.camel.spring.boot.CamelContextConfiguration and specify additional.properties location directly to PropertiesComponent won't resolve the issue as beans initialization happens before call to the .apache.camel.spring.boot.CamelContextConfiguration#beforeApplicationStart

ADDITION: As dependency of the project only the implementation(".apache.camel.springboot:camel-spring-boot-starter:4.10.2")

发布评论

评论列表(0)

  1. 暂无评论