In the classic web.xml type configuration you could configure context parameters like so
web.xml
... <context-param> <param-name>p-name</param-name> <param-value>-value</param-value> </context-param> ...
How is this achieved in spring-boot. I have a filter that requires parameters.
I'm using @EnableAutoConfiguration
and have included <artifactId>spring-boot-starter-jetty</artifactId>
in my pom.
You can set parameters on the whole ServletContext
by declaring a ServletContextInitializer
bean:
@Bean public ServletContextInitializer initializer() { return new ServletContextInitializer() { @Override public void onStartup(ServletContext servletContext) throws ServletException { servletContext.setInitParameter("p-name", "-value"); } }; }
Update: in Spring Boot 1.2 using a ServletContextInitializer
is no longer necessary. You can now configure a parameter on the ServletContext
in a single line in application.properties
:
server.context_parameters.p-name=-value
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With