作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在经典的 web.xml 类型配置中,您可以像这样配置上下文参数
web.xml
...
<context-param>
<param-name>p-name</param-name>
<param-value>-value</param-value>
</context-param>
...
这是如何在 spring-boot 中实现的。我有一个需要参数的过滤器。
我正在使用@EnableAutoConfiguration
并已包括<artifactId>spring-boot-starter-jetty</artifactId>
在我的 pom 中。
最佳答案
您可以使用server.servlet.context-parameters
应用程序属性来设置参数。例如:
server.servlet.context-parameters.p-name=p-value
在不再支持的 Spring Boot 1.x 中,此属性被命名为 server.context-parameters
:
servlet.context-parameters=p-name=p-value
或者,您可以通过声明 ServletContextInitializer
bean 以编程方式配置参数:
@Bean
public ServletContextInitializer initializer() {
return new ServletContextInitializer() {
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
servletContext.setInitParameter("p-name", "-value");
}
};
}
关于spring-mvc - 如何在 spring-boot 中设置 context-param,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26639475/
我是一名优秀的程序员,十分优秀!