I've got a stateless session bean which instantiates a plain java class. This class' constructor actually has a code like this: -
ClassLoader classloader = Thread.currentThread().getContextClassLoader();
InputStream inputstream = classloader.getResourceAsStream("SomePropertyFile");
I'm currently using WebLogic 6.1 Most of the time it works. But at certain times it gives a nullpointer on reading this. Is there a flaw in doing this approach that I'm not aware of? Is this some sort of runaway thread?
Any hint would be much appreciated.
This is illegla in EJB
1) A class running in an EJB container cannot try to access the ClassLoader
2) A class running in an EJB cannot use any calls on Thread.
You'll have to change the code in the class you are calling to not do this. You can instead do something like
URL resource = MyClassName.class.getResource(SOME_PROPS_FILE);
The Scupper Group
dave at scuppergroup dot com
to accesses the properties file on the server, this should help..
we have the same scenerio...
ResourceBundle rsourceBundle = ResourceBundle.getBundle (BundleName);
i really donot know why exactly the ejbclassloader should be utilized for this purpose?? let me know if there is a definite purpose.
You're right! "ResourceBundle rsourceBundle = ResourceBundle.getBundle (BundleName); " is probably one of the best ways in doing it. Thanks.
Any best strategy in such a way that the whole app could just read the resource once, as oppose to having each Stateless Session Bean reading it when they are being called?
probably we should consider a controller servlet init process loading the resource bundle when the application server is started.