Several notes:
- You should prefer the
ClassLoader
as returned byThread#getContextClassLoader()
.ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
This returns the parentmost classloader which has access to all resources. TheClass#getClassLoader()
will only return the (child) classloader of the class in question which may not per se have access to the desired resource. It will always work in environments with a single classloader, but not always in environments with a complex hierarchy of classloaders like webapps. - The
/WEB-INF
folder is not in the root of the classpath. The/WEB-INF/classes
folder is. So you need to load the properties files relative to that.classLoader.getResourceAsStream("/auth.properties");
If you opt for using theThread#getContextClassLoader()
, remove the leading/
.
沒有留言:
張貼留言