HTTP TRACE / TRACK Methods Allowed问题修复
import org.apache.catalina.Context;
import org.apache.tomcat.util.descriptor.web.SecurityCollection;
import org.apache.tomcat.util.descriptor.web.SecurityConstraint;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory;
import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory;
import org.springframework.context.annotation.Bean;
@SpringBootApplication
public class DemoApplication{
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);}@Beanpublic EmbeddedServletContainerFactory servletContainer() {
TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory() {
protected void postProcessContext(Context context) {
SecurityConstraint securityConstraint = new SecurityConstraint();securityConstraint.setUserConstraint("CONFIDENTIAL");SecurityCollection collection = new SecurityCollection();collection.addPattern("/*");collection.addMethod("HEAD");collection.addMethod("PUT");collection.addMethod("DELETE");collection.addMethod("OPTIONS");collection.addMethod("TRACE");collection.addMethod("COPY");collection.addMethod("SEARCH");collection.addMethod("PROPFIND");securityConstraint.addCollection(collection);context.addConstraint(securityConstraint);}};tomcat.addConnectorCustomizers(connector -> {
connector.setAllowTrace(true);});return tomcat;}
}