首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >不同端口上的Spring 2.1.0管理服务器端口

问不同端口上的Spring 2.1.0管理服务器端口
EN

Stack Overflow用户
提问于 2018-11-14 10:28:51
回答 1查看 3.1K关注 0票数 3

在我的spring 2.0应用程序中,我让主应用程序监听端口1234,我想让管理服务器在1235上运行。

因此,在我的配置文件中,我设置:

management.server.port=1235

由于以下错误,我的服务器无法启动:

错误2018-11-1405:20:14.958主SpringApplication -应用程序运行失败的org.springframework.beans.FatalBeanException: ServletWebServerFactory实现com.my.MyApplication$2无法实例化.若要允许使用单独的管理端口,应该在org.springframework.boot.actuate.autoconfigure.web.servlet.ServletManagementContextFactory.determineServletWebServerFactoryClass(ServletManagementContextFactory.java:77) ~spring-boot-actuator-autoconfigure-2.1.0.RELEASE.jar:2.1.0.RELEASE at org.springframework.boot.actuate.autoconfigure.web.servlet.ServletManagementContextFactory.registerServletWebServerFactory(ServletManagementContextFactory.java:64) ~spring-boot-actuator-autoconfigure-2.1.0.RELEASE.jar:2.1.0.RELEASE上使用顶级类或静态内部类。在org.springframework.boot.actuate.autoconfigure.web.servlet.ServletManagementContextFactory.createManagementContext(ServletManagementContextFactory.java:52) ~spring-boot-actuator-autoconfigure-2.1.0.RELEASE.jar:2.1.0.RELEASE at org.springframework.boot.actuate.autoconfigure.web.server.ManagementContextAutoConfiguration$DifferentManagementContextConfiguration.afterSingletonsInstantiated(ManagementContextAutoConfiguration.java:143) ~spring-boot-actuator-autoconfigure-2.1.0.RELEASE.jar:2.1.0.RELEASE at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:863) ~spring 5.1.2.RELEASE.jar:5.1.2.在org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:863) ~spring-context-5.1.2.RELEASE.jar:5.1.2.RELEASE at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:546) ~spring-context-5.1.2.RELEASE.jar:5.1.2.RELEASE atRELEASE.jar:2.1.0.RELEASE.jar: org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) -2.1.0.RELEASE.JAR:2.1.0.RELEASE.JAR:2。1.0. org.springframework.boot.SpringApplication.run(SpringApplication.java:316)弹簧的1.0.RELEASE 2.1.0.RELEASE.jar:2.1.0.在org.springframework.boot.SpringApplication.run(SpringApplication.java:1260)弹簧-2.1.0 RELEASE.jar:2.1.0在org.springframework.boot.SpringApplication.run(SpringApplication.java:1248)弹簧-在org.springframework.boot.SpringApplication.run(SpringApplication.java:1248)弹簧-启动-2.1.0 RELEASE.jar2.1.0. com.my.MyApplication.main(EmsApplication.java:51) main/:?

如果我移除这个:

代码语言:javascript
复制
@Bean
public TomcatServletWebServerFactory containerFactory() {
    return new TomcatServletWebServerFactory() {
        @Override
        protected void customizeConnector(Connector connector) {
            int maxSize = 50000000;
            super.customizeConnector(connector);
            connector.setMaxPostSize(maxSize);
            connector.setMaxSavePostSize(maxSize);
            if (connector.getProtocolHandler() instanceof AbstractHttp11Protocol) {

                ((AbstractHttp11Protocol <?>) connector.getProtocolHandler()).setMaxSwallowSize(maxSize);
            }
        }
        t
    };

}

那就成功了。

如何解决这个问题?

谢谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-11-14 17:24:39

您的TomcatWebServerFactory子类是一个匿名内部类。它需要是静态内部类或顶级类,以便能够实例化:

代码语言:javascript
复制
@Bean
public TomcatServletWebServerFactory containerFactory() {
    return new CustomTomcatServletWebServerFactory();
}

static final class CustomTomcatServletWebServerFactory
        extends TomcatServletWebServerFactory {

    @Override
    protected void customizeConnector(Connector connector) {
        int maxSize = 50000000;
        super.customizeConnector(connector);
        connector.setMaxPostSize(maxSize);
        connector.setMaxSavePostSize(maxSize);
        if (connector.getProtocolHandler() instanceof AbstractHttp11Protocol) {
            ((AbstractHttp11Protocol<?>) connector.getProtocolHandler())
                    .setMaxSwallowSize(maxSize);
        }
    }

}

或者,您可以使用自定义程序而不是子类TomcatServletWebServerFactory。

代码语言:javascript
复制
@Bean
public WebServerFactoryCustomizer<TomcatServletWebServerFactory> tomcatCustomizer() {
    return (tomcat) -> tomcat.addConnectorCustomizers((connector) -> {
        int maxSize = 50000000;
        connector.setMaxPostSize(maxSize);
        connector.setMaxSavePostSize(maxSize);
        if (connector.getProtocolHandler() instanceof AbstractHttp11Protocol) {

            ((AbstractHttp11Protocol<?>) connector.getProtocolHandler())
                    .setMaxSwallowSize(maxSize);
        }
    });
}
票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53298008

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档