If you are using spring boot or working towards java config, you might have or are looking to get away from web.xml based configured web applications. Various frameworks, such as JSF, rely heavily on context parameters for initialization and configuration. If you aren't familiar,
< context-param> is available to all parts of the web application and typically can be retrieved by
As you are working at ripping away each piece of the web.xml, one item that wasn't so obvious was how to set
< context-param> in java config. The Servlet 3.0 ServletContext API allows for setting init-params, context-params among other things programmatically. One way to get a hook into servlet context in spring is to implement
WebApplicationInitializer. WebApplicationInitializer classes are detected automatically by SpringServletContainerInitializer which itself is bootstrapped by a servlet 3.0 container.
Below is snapshot of how to configure context parameters in servlet 3.0 while using spring.
|Servlet 2.0||Servlet 3.0|