springboot2的tomcatConfig的写法
程序员文章站
2022-07-15 10:24:34
...
springboot 1.4 使用的tomcatConfig中代码如下
@Bean
public TomcatServletWebServerFactory servletContainer() {
TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory() {// 1
protected void postProcessContext(Context context) {
SecurityConstraint securityConstraint = new SecurityConstraint();
securityConstraint.setUserConstraint("CONFIDENTIAL");
SecurityCollection collection = new SecurityCollection();
collection.addPattern("/*");
collection.addMethod("PUT");
collection.addMethod("DELETE");
collection.addMethod("CONNECT");
collection.addMethod("OPTIONS");
collection.addMethod("PATCH");
collection.addMethod("PROPFIND");
collection.addMethod("PROPPATCH");
collection.addMethod("MKCOL");
collection.addMethod("COPY");
collection.addMethod("MOVE");
collection.addMethod("LOCK");
collection.addMethod("UNLOCK ");
collection.addMethod("TRACE");
collection.addMethod("HEAD");
securityConstraint.addCollection(collection);
context.addConstraint(securityConstraint);
}
};
升级springboot2之后,发现EmbeddedServletContainerFactory 没有了。然后发现是springboot2改写法了,改成如下写法,记录一下
@Bean
public TomcatServletWebServerFactory servletContainer() {
TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory () {// 1
protected void postProcessContext(Context context) {
SecurityConstraint securityConstraint = new SecurityConstraint();
securityConstraint.setUserConstraint("CONFIDENTIAL");
SecurityCollection collection = new SecurityCollection();
collection.addPattern("/*");
collection.addMethod("PUT");
collection.addMethod("DELETE");
collection.addMethod("CONNECT");
collection.addMethod("OPTIONS");
collection.addMethod("PATCH");
collection.addMethod("PROPFIND");
collection.addMethod("PROPPATCH");
collection.addMethod("MKCOL");
collection.addMethod("COPY");
collection.addMethod("MOVE");
collection.addMethod("LOCK");
collection.addMethod("UNLOCK ");
collection.addMethod("TRACE");
collection.addMethod("HEAD");
securityConstraint.addCollection(collection);
context.addConstraint(securityConstraint);
}
};
上一篇: springboo2开启http2
下一篇: SpringBoot日志配置