git.net

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

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


Oh thanks! I was going to raise a jira issue after I verified it worked on
my end.

I removed the extends CamelTestSupport

and removed the

createRouteBuilder in the test class so the route is being created by the
"production" route builder instead.

it worked.


I would be very happy if CamelTestSupport upon detecting spring-boot is in
use, to just throw an error sayibg
"hey, you are using camel-spring-boot, don't use CamelTestSupport". That'd
be more than enough. I've used
CamelTestSupport for so long that I didn't realize this was the wrong thing
to do for spring-boot camel app.


On Wed, Mar 21, 2018 at 9:02 AM, Claus Ibsen <claus.ibsen@xxxxxxxxx> wrote:

> Hi
>
> I logged a ticket to not forget about this, to see if we can improve
> it (and detect that the class is IoC'ed by Spring / Spring-Boot and
> then avoid the 2x IoC
> https://issues.apache.org/jira/browse/CAMEL-12389
>
> On Tue, Mar 20, 2018 at 4:15 PM, Claus Ibsen <claus.ibsen@xxxxxxxxx>
> wrote:
> > Hi
> >
> > Yeah for SB then it tend to not do that, see the couple of spring-boot
> > testing examples here
> > https://github.com/camelinaction/camelinaction2/tree/master/chapter9
> >
> > Your Camel routes tend to be in their own classes, that you would run
> > "in production".
> >
> > What you do with the embedded inlined route is more for testing Camel
> > internally or some other kind of testing.
> >
> > The issue you hit with CamelTestSupport is possible to fix, you can
> > log a JIRA. I havent had found the time to fix it yet.
> > And CamelTestSpringSupport could potentially be improved for running
> > with Spring Boot too.
> >
> >
> >
> > On Tue, Mar 20, 2018 at 3:59 PM, Wilson MacGyver <wmacgyver@xxxxxxxxx>
> wrote:
> >> Oh really? So would you suggest I just don’t extend any base class at
> all?
> >>
> >> On Tue, Mar 20, 2018 at 10:53 AM Claus Ibsen <claus.ibsen@xxxxxxxxx>
> wrote:
> >>
> >>> On Tue, Mar 20, 2018 at 3:21 PM, Wilson MacGyver <wmacgyver@xxxxxxxxx>
> >>> wrote:
> >>> > Oh I didn’t know that there was CamelSpringTestSupport! Thank you!
> Will
> >>> try
> >>> > it
> >>> >
> >>>
> >>> Just a mind that CamelSpringTestSupport was created many years ago
> >>> before Spring Boot,
> >>> and thus is more suitable for old fashioned Spring apps such as WARs
> etc.
> >>>
> >>>
> >>> > On Tue, Mar 20, 2018 at 6:09 AM Claus Ibsen <claus.ibsen@xxxxxxxxx>
> >>> wrote:
> >>> >
> >>> >> 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
> >>> >>
> >>>
> >>>
> >>>
> >>> --
> >>> Claus Ibsen
> >>> -----------------
> >>> http://davsclaus.com @davsclaus
> >>> Camel in Action 2: https://www.manning.com/ibsen2
> >>>
> >
> >
> >
> > --
> > Claus Ibsen
> > -----------------
> > http://davsclaus.com @davsclaus
> > Camel in Action 2: https://www.manning.com/ibsen2
>
>
>
> --
> Claus Ibsen
> -----------------
> http://davsclaus.com @davsclaus
> Camel in Action 2: https://www.manning.com/ibsen2
>



-- 
Omnem crede diem tibi diluxisse supremum.


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

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