castor-data-binding / castor

http://castor-data-binding.github.io/castor/
35 stars 29 forks source link

User property file classpath loading assumes a flat classpath #50

Open jamesnetherton opened 8 years ago

jamesnetherton commented 8 years ago

The AbstractProperties class attempts to load a properties file with:

URL url = getClass().getResource(filename);

This is not guaranteed to work in modular class loading environments such as in OSGi or some JavaEE containers.

Perhaps it'd be better to use the _applicationClassLoader to load resources. But even this is currently not guaranteed to work at present because XMLContext forces a specific ClassLoader, which itself may not be the correct one.

wguttmn commented 8 years ago

Fell free to provide a pull request for both "points", in other words one that fixes the problem in AbstractProperties and another one that highlights the second point with an example that can be used to (re)play the problem.

jamesnetherton commented 8 years ago

Thanks, I'll try to put a pull request together shortly.

Just to clarify, you want me to provide a second PR with an example that shows why the _applicationClassLoader may not be the correct ClassLoader, based on the one provided by XMLContext (before making any changes to fix this)?

If so, what form does this take? A unit test? Or an example application like the ones in the examples directory.

wguttmn commented 8 years ago

Yes, a Unit test would be fine. In case you want to show me something in the context of a webapp, why not provide me with a Spring boot app that highlights the problem(s) at hand.