git.net

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: @PropertyInject vs @Value in camel-spring-boot


Hi

Okay so the issue is that you have a spring-boot application and you
extend CamelTestSupport which performs some initialization that happen
to do bean post processing as well, but under the assumption it was
not running with Spring (we can likely improve this in
CamelTestSupport).

But you should either extend CamelSpringTestSupport or not extend a
base class at all.

On Sun, Mar 18, 2018 at 7:37 PM, Wilson MacGyver <wmacgyver@xxxxxxxxx> wrote:
> Hi
>
> I'm using camel 2.21.0, spring boot 1.5.10
>
> I put together strip down version of what I'm seeing at
>
> https://github.com/wmacgyver/camel-spring-boot-property-bug
>
>
>
> Running ExampleRouteTest method testWithContent
>
> @Value("${fromUser}")
> private String fromUser;
>
> @Value("${toUser}")
> private String toUser;
>
> works correctly.
>
> Both have values from applciation.properties
>
>
> .to("smtp://localhost?from={{fromUser}}&to={{toUser}}&subject=Test+Done");
>
> Does not.
>
>
> You get
>
> org.apache.camel.FailedToCreateRouteException: Failed to create route
> route1 at: >>> To[smtp://localhost?from={{fromUser}}&to={{toUser}}&subject=Test+Done]
> <<< in route: Route(route1)[[From[direct:startRoute]] ->
> [SetBody[simple{S... because of Property with key [fromUser] not found
> in properties from text:
> smtp://localhost?from={{fromUser}}&to={{toUser}}&subject=Test+Done
>
> ...
> Caused by: java.lang.IllegalArgumentException: Property with key
> [fromUser] not found in properties from text:
> smtp://localhost?from={{fromUser}}&to={{toUser}}&subject=Test+Done
>         at org.apache.camel.component.properties.DefaultPropertiesParser$ParsingContext.getPropertyValue(DefaultPropertiesParser.java:270)
>         at org.apache.camel.component.properties.DefaultPropertiesParser$ParsingContext.readProperty(DefaultPropertiesParser.java:156)
>         at org.apache.camel.component.properties.DefaultPropertiesParser$ParsingContext.doParse(DefaultPropertiesParser.java:115)
>         at org.apache.camel.component.properties.DefaultPropertiesParser$ParsingContext.parse(DefaultPropertiesParser.java:99)
>         at org.apache.camel.component.properties.DefaultPropertiesParser.parseUri(DefaultPropertiesParser.java:62)
>         at org.apache.camel.component.properties.PropertiesComponent.parseUri(PropertiesComponent.java:235)
>         at org.apache.camel.component.properties.PropertiesComponent.parseUri(PropertiesComponent.java:178)
>         at org.apache.camel.impl.DefaultCamelContext.resolvePropertyPlaceholders(DefaultCamelContext.java:2550)
>         at org.apache.camel.model.ProcessorDefinitionHelper.resolvePropertyPlaceholders(ProcessorDefinitionHelper.java:735)
>         at org.apache.camel.model.ProcessorDefinition.makeProcessorImpl(ProcessorDefinition.java:537)
>         at org.apache.camel.model.ProcessorDefinition.makeProcessor(ProcessorDefinition.java:523)
>         at org.apache.camel.model.ProcessorDefinition.addRoutes(ProcessorDefinition.java:239)
>         at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:1300)
>
>
>
>
> Thanks
>
>
> On Sun, Mar 18, 2018 at 4:49 AM, Claus Ibsen <claus.ibsen@xxxxxxxxx> wrote:
>
>> Hi
>>
>> Can you post the stacktrace, and can you tell a bit about where you
>> put that @ProjectInject.
>> And what version of camel and SB are you using. And have you tried
>> with a newer version
>>
>> On Sat, Mar 17, 2018 at 6:03 AM, Wilson MacGyver <wmacgyver@xxxxxxxxx>
>> wrote:
>> > Hi there,
>> >
>> > I'm using camel-spring-boot
>> >
>> > I add
>> >
>> > hello = world in my application.properties
>> >
>> > I notice if I use
>> >
>> > @PropertyInject("hello")
>> > private String hello
>> >
>> > I get
>> >
>> >  Property with key not found in properties from text
>> >
>> > but if I use
>> >
>> > @Value("${hello}")
>> >
>> > it works.
>> >
>> > this surprise me, since I was under the impression that per doc, camel
>> uses
>> > spring to resolve all the properties if you use camel-spring-boot. but
>> yet
>> > somehow spring can find the value from applicaiton.properties, but camel
>> > can not?
>> >
>> > am I missing something?
>> >
>> > --
>> > Omnem crede diem tibi diluxisse supremum.
>>
>>
>>
>> --
>> Claus Ibsen
>> -----------------
>> http://davsclaus.com @davsclaus
>> Camel in Action 2: https://www.manning.com/ibsen2
>>
>
>
>
> --
> Omnem crede diem tibi diluxisse supremum.



-- 
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2



( ! ) Warning: include(msgfooter.php): failed to open stream: No such file or directory in /var/www/git/apache-camel-users/msg03164.html on line 209
Call Stack
#TimeMemoryFunctionLocation
10.0006368696{main}( ).../msg03164.html:0

( ! ) Warning: include(): Failed opening 'msgfooter.php' for inclusion (include_path='.:/var/www/git') in /var/www/git/apache-camel-users/msg03164.html on line 209
Call Stack
#TimeMemoryFunctionLocation
10.0006368696{main}( ).../msg03164.html:0