Yow - that works!

Thanks, Claus! I understand the IoC aspect of it now.

I still don't understand why getProperty("name") can't work when 
resolvePropertyPlaceholders("{{name}}") will.
In my mind they should be going to the same set of name/value to look up 'name' 
but they're not. Why is that?

Thank you very much,
-Steve

> -----Original Message-----
> From: Claus Ibsen [mailto:claus.ib...@gmail.com]
> Sent: Wednesday, November 16, 2016 4:25 PM
> To: users@camel.apache.org
> Subject: Re: Seeking to understand properties
> 
> That is because @PropertyInject is IoC injected by Camel or Spring when you
> use it to setup the beans. But in your unit test you create that class 
> yourself
> with the new constructor, then its not dependency injection for such things.
> 
> Instead use Camel to create it with
> 
> return context().getInjector().newInstance(MyRouteBuilder.class);
> 
> 
> 
> On Wed, Nov 16, 2016 at 6:51 PM, Steve Huston <shus...@riverace.com>
> wrote:
> > Thank you for the responses thus far. I still have some confusion and an
> observation.
> >
> > First, I find it very confusing and non-intuitive that the "properties" in
> CamelContext are apparently not the "properties" in property placeholder.
> From my reading of the various doc pages it seemed like property
> placeholders are ways to get values from the properties substituted into
> routes. But it seems like maybe there are more than one set, or type, of
> properties. Is this true?
> >
> > My observation... in my test below I added @PropertyInject("datafile") on
> the line above "private String filename;" and that _did_ get the value set via
> useOverridePropertiesWithPropertiesComponent(). However, if I add the
> same @PropertyInject to a member in the MyRouteBuilder class, that _does
> not_ get the value.
> >
> > Can someone please help me understand what's going on here?
> >
> > Thanks,
> > -Steve
> >
> >> -----Original Message-----
> >> From: Claus Ibsen [mailto:claus.ib...@gmail.com]
> >> Sent: Wednesday, November 16, 2016 9:59 AM
> >> To: users@camel.apache.org
> >> Subject: Re: Seeking to understand properties
> >>
> >> Hi
> >>
> >> context().getProperty("dataFile");
> >>
> >> is not property placeholders. Its just generic key/value pairs on
> >> CamelContext. See the javadoc of the API.
> >>
> >> For property placeholders take a look at
> >> http://camel.apache.org/using- propertyplaceholder.html
> >>
> >> On Tue, Nov 15, 2016 at 11:58 PM, Steve Huston <shus...@riverace.com>
> >> wrote:
> >> > I am struggling to understand something I fear is very basic, but I
> >> > just don't
> >> see it. Hoping someone can help me understand this.
> >> >
> >> > Properties... I can use them in route definitions, but I don't seem
> >> > to be able
> >> to obtain their values in regular Java code.
> >> >
> >> > Example (using Camel 2.16.3):
> >> >
> >> > I have a route builder:
> >> >
> >> > public class MyRouteBuilder extends RouteBuilder {
> >> >     public void configure() {
> >> >         from("file:{{dataFile}}?noop=true")
> >> >          .to("file:target/messages/others");
> >> >     }
> >> > }
> >> >
> >> > And a unit test:
> >> >
> >> > @RunWith(JUnit4.class)
> >> > public class UnitTest extends CamelTestSupport {
> >> >
> >> >         private String fileName;
> >> >
> >> >             @Override
> >> >             protected RouteBuilder createRouteBuilder() {
> >> >                 return new MyRouteBuilder();
> >> >             }
> >> >
> >> >             @Override
> >> >             public Boolean ignoreMissingLocationWithPropertiesComponent()
> {
> >> >                 return true;
> >> >             }
> >> >
> >> >             @Override
> >> >             protected Properties
> >> useOverridePropertiesWithPropertiesComponent() {
> >> >                     Properties override = new Properties();
> >> >                     override.put("dataFile", "overridden-file");
> >> >                     return override;
> >> >             }
> >> >
> >> >             @Test
> >> >                 public void testPropertyGetting() throws Exception {
> >> >                 fileName = context().getProperty("dataFile");
> >> >                 assert(fileName != null);
> >> >             }
> >> > }
> >> >
> >> > When I run this test, the output includes:
> >> >
> >> > INFO  Route: route1 started and consuming from:
> >> > Endpoint[file://overridden-file?noop=true]
> >> >
> >> > So the override property set above did get filled into the route
> definition.
> >> > However, when I try to get the property in the
> >> > testPropertyGetting() method, the value is null
> >> >
> >> > Why???
> >> >
> >> > -Steve
> >> >
> >>
> >>
> >>
> >> --
> >> 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

Reply via email to