spring boot多个端口启动项目访问 报错:"Invalid character found in method name. HTTP method names must be tokens"

多端口配置 springboot2 写法

    @Bean
    public TomcatServletWebServerFactory servletContainer() {
        TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory() {
            @Override
            protected void postProcessContext(Context context) {
                SecurityConstraint constraint = new SecurityConstraint();
                constraint.setUserConstraint("CONFIDENTIAL");
                SecurityCollection collection = new SecurityCollection();
                collection.addPattern("/*");
                constraint.addCollection(collection);
                context.addConstraint(constraint);
            }
        };
        tomcat.addAdditionalTomcatConnectors(additionalConnector());
        return tomcat;
    }

    private Connector[] additionalConnector() {
        if (StringUtils.isBlank(this.additionalPorts)) {
            return null;
        }
        String[] ports = this.additionalPorts.split(",");
        List<Connector> result = new ArrayList<>();
        for (String port : ports) {
            Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
            connector.setPort(Integer.valueOf(port));
            result.add(connector);
        }
        return result.toArray(new Connector[]{});
    }

application.properties

    server.additionalPorts=81,83,85

正常启动

.....
2019-06-04 15:25:30.743  INFO 3028 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
2019-06-04 15:25:30.960  INFO 3028 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) 81 (http) 83 (http) 85 (http) with context path ''
....

访问报错

Invalid character found in method name. HTTP method names must be tokens 

解决方法

 配置里把这句注释了,“CONFIDENTIAL” 不明白的翻译下?
//constraint.setUserConstraint("CONFIDENTIAL");

猜你喜欢

转载自blog.csdn.net/zhaojunjie_cc/article/details/90769952