Is there any way in the Servlet API to access properties specified in web.xml (such as initialization parameters) from within a Bean or Factory class that is not associated at all with the web container?
For example, I'm writing a Factory class, and I'd like to include some logic within the Factory to check a hierarchy of files and configuration locations to see which if any are available to determine which implementation class to instantiate - for example, 1) a properties file in the classpath, 2) a web.xml parameter, 3) a system property, or 4) some default logic if nothing else is available.
I'd like to be able to do this without injecting any reference to ServletConfig
or anything similiar to my Factory - the code should be able to run ok outside of a Servlet Container.
This might sound a little bit uncommon, but I'd like for this component I'm working on to be able to be packaged with one of our webapps, and also be versatile enough to be packaged with some of our command-line tools without requiring a new properties file just for my component - so I was hoping to piggyback on top of other configuration files such as web.xml.
If I recall correctly, .NET has something like Request.GetCurrentRequest()
to get a reference to the currently executing Request
- but since this is a Java app I'm looking for something simliar that could be used to gain access to ServletConfig
.