Reputation: 903
I'm trying to inject values from the application.properties file in a camel processor but it returns null
. I also tried adding the @Component
annotation but this breaks the application.
public class MyProcessor implements Processor {
@Value("${myProperty.path}")
public String path;
public void process(Exchange exchange) throws Exception {
System.out.println(path);
}
}
I'm new to both camel and spring. What could I do to read properties from the application.properties file in the processor class?
Upvotes: 0
Views: 1041
Reputation: 7005
Property injection with @Value
only works with container managed beans.
Therefore, you are on the right track with @Component
, but I suspect (as mentioned in the comments) that your MyProcessor
is not such a bean.
If you do one of these in your Camel route, then your Processor is NOT such a bean.
.process(MyProcessor.class)
.process(new MyProcessor())
Instead you have to annotate your Processor with @Component
, hold an instance variable of it in your Camel Route class and then reference the instance.
.process(myProcessorInstance) <-- variable
Upvotes: 2