Spring Boot 2.1.0管理服务器端口位于其他端口上

时间:2018-11-14 10:28:51

标签: spring spring-boot spring-boot-actuator

在我的spring boot 2.0应用程序中,我的主应用程序在端口1234上侦听,我希望管理服务器在1235上运行。

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

management.server.port=1235

我的服务器无法启动,出现以下错误:

  

[错误] 2018-11-14 05:20:14.958 [main] 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]       在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]       在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 ]       在org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:863)〜[spring-beans-5.1.2.RELEASE.jar:5.1.2.RELEASE]       在org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:863)〜[spring-context-5.1.2.RELEASE.jar:5.1.2.RELEASE]       在org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:546)〜[spring-context-5.1.2.RELEASE.jar:5.1.2.RELEASE]       在org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140)〜[spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]       在org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775)上[spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]       在org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)上[spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]       在org.springframework.boot.SpringApplication.run(SpringApplication.java:316)上[spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]       在org.springframework.boot.SpringApplication.run(SpringApplication.java:1260)上[spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]       在org.springframework.boot.SpringApplication.run(SpringApplication.java:1248)上[spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]       在com.my.MyApplication.main(EmsApplication.java:51)[main / :?]

如果我删除了此内容:

@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
    };

}

然后它起作用。

如何解决这个问题?

谢谢!

1 个答案:

答案 0 :(得分:1)

您的<html> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <body> <table> <tr id=tablegrid> <td>1</td> <td>2</td> </tr> </table> </body> </html>子类是匿名内部类。它必须是静态的内部类或顶级类,以便可以实例化:

TomcatWebServerFactory

或者,您可以使用定制程序,而不是对@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