Camel properties file not found in class path

假装没事ソ 提交于 2019-12-12 02:17:24

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!