Reputation: 27
I'm trying to read some parameters from my servlet init-params that reside on my web.xml, and make them accesible through variables in my program. I thought I could use the equivalent to the init() method of the HttpServlet.
There's a solution in this question : init method in jersey jax-rs web service.
I thought the first solution might work for me but the problem is that the ServletContextEvent only has access to the paramters defined in the context-param tags and I need them from my own servlet init-params values.
I wouldn't like to move the parameters from my servlet into the context-param tags because the parameters are really only relevant to that specific servlet.
Can someone point me in the right direction?
Upvotes: 0
Views: 947
Reputation: 208944
With Jersey, all the init-params are available in a Configuration
object that you can inject almost anywhere you want; resources, filters, etc.
@Path("test")
public class SomeResource {
@Context
private Configuration configuration;
@GET
public String get() {
return (String) configuration.getProperty(InitParams.MY_INIT_PARAM);
}
}
See Also:
Upvotes: 1