0

I've successfully used properties in Camel routes. This time I need to read values from a file in an auxiliary class that does not define a Camel route.

This is the property-placeholder portion of my blueprint:

<cm:property-placeholder persistent-id="my.package.pph" update-strategy="reload">
    <cm:default-properties>
        <cm:property name="myFile" value="C:\\temp\\myFile.xml" />
    </cm:default-properties>
</cm:property-placeholder>

And this is how I declared that I want that value in my class:

<bean id="myConverter" class="my.package.name.MyClass">
    <property name="fileName" value="${myFile}" />
</bean>

Then, in my class, I declared a variable with the same name as the property in the bean and generated the getter and setter in Eclipse. The variable never gets the value from the blueprint.

Is this possible, or should I look for alternatives? Thanks

noitib
  • 148
  • 1
  • 13

1 Answers1

2

You can inject properties into your beans using the PropertyInject annotation

@PropertyInject("myFile")
private String fileName;

With this there should be no need to do what you're trying to achieve in your last code block.

Although, for the sake of education, if you do this:

<bean id="myConverter" class="my.package.name.MyClass">
    <property name="fileName" value="${myFile}" />
</bean>

You can get the value in your bean like this:

private String fileName;

public void setFileName(String myFile) {
    this.fileName = myFile;
}
Erik Karlstrand
  • 1,479
  • 9
  • 22