【发布时间】:2019-04-17 06:57:29
【问题描述】:
在我的 spring boot 2.0 应用程序中,我的主应用程序在 1234 端口上侦听,我想让管理服务器在 1235 上运行。
所以在我的配置文件中,我设置了:
management.server.port=1235
我的服务器无法启动,出现以下错误:
[ERROR] 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
};
}
然后就可以了。
如何解决这个问题?
谢谢!
【问题讨论】:
-
删除这个问题就不存在了:
-
ServletWebServerFactory implementation com.my.MyApplication$2那个类是什么样子的? -
@DarrenForsythe 即
TomcatServletWebServerFactory。 -
您是否尝试过定义 bean
TomcatServletWebServerFactoryCustomizer并调用addConnectorCustomizers而不是TomcatServletWebServerFactory?
标签: spring spring-boot spring-boot-actuator