问题
I am tring to load the resource: src/com/company/my.properties
, but it can't be found on the classpath.
Error
Failed to create route route1: Route(route1)[[From[properties:{{fromroute}}]] ->
[Choice[[When[... because of Failed to resolve endpoint: properties://%7B%7Bfromroute%7D%7D due to:
Properties file com/company/my.properties not found in classpath
- camel core:2.18
- camel properties read refer : Doc
The my.properties
file contains a 'fromroute' key:
fromroute=file:/a/b
The following snippet shows how I'm trying to load the file.
PropertiesComponent pc = new PropertiesComponent();
pc.setLocation("classpath:com/company/my.properties");
context.addComponent("properties", pc);
....
from("properties:{{fromroute}}")
....
回答1:
my.properties
file should be moved in to src/main/resources
(not src/com/company
)
and update the setLocation()
path:
pc.setLocation("my.properties");
回答2:
For the classloader to find a resource, it needs to be located in src/main/resources/, e.g. in your case: src/main/resources/com/company/my.properties, otherwise the resource won't end up in the JAR file and its not accessible at runtime.
Dependent on the type of ClassLoader you're using to load the resource, you either need to include or exclude the package name.
For example:
getClass().getClassLoader().getResourceAsStream("my.properties");
Thread.currentThread().getContextClassLoader().getResourceAsStream("/com/company/my.properties");
来源:https://stackoverflow.com/questions/41691539/camel-properties-file-not-found-in-class-path