Spring boot 2.1.0 management server port on different port












1















In my spring boot 2.0 application, I have the main application listening on port 1234, I want to have the management server running on 1235.



So in my config file, I set:



management.server.port=1235



My server fails to start, with this error:




[ERROR] 2018-11-14 05:20:14.958 [main] SpringApplication - Application run failed
org.springframework.beans.FatalBeanException: ServletWebServerFactory implementation com.my.MyApplication$2 cannot be instantiated. To allow a separate management port to be used, a top-level class or static inner class should be used instead
at 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]
at 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-beans-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at 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]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) ~[spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775) [spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:316) [spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260) [spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248) [spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at com.my.MyApplication.main(EmsApplication.java:51) [main/:?]




If I remove this:



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

}


then it works.



How to solve this problem?



thanks!










share|improve this question

























  • The problem doesn't exist if I remove this:

    – The MW
    Nov 14 '18 at 10:36











  • ServletWebServerFactory implementation com.my.MyApplication$2 what does that class look like?

    – Darren Forsythe
    Nov 14 '18 at 10:37











  • @DarrenForsythe that is the TomcatServletWebServerFactory .

    – The MW
    Nov 14 '18 at 10:52











  • Have you tried to define bean TomcatServletWebServerFactoryCustomizer and call addConnectorCustomizers instead TomcatServletWebServerFactory?

    – Alexander Pankin
    Nov 14 '18 at 15:37


















1















In my spring boot 2.0 application, I have the main application listening on port 1234, I want to have the management server running on 1235.



So in my config file, I set:



management.server.port=1235



My server fails to start, with this error:




[ERROR] 2018-11-14 05:20:14.958 [main] SpringApplication - Application run failed
org.springframework.beans.FatalBeanException: ServletWebServerFactory implementation com.my.MyApplication$2 cannot be instantiated. To allow a separate management port to be used, a top-level class or static inner class should be used instead
at 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]
at 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-beans-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at 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]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) ~[spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775) [spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:316) [spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260) [spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248) [spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at com.my.MyApplication.main(EmsApplication.java:51) [main/:?]




If I remove this:



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

}


then it works.



How to solve this problem?



thanks!










share|improve this question

























  • The problem doesn't exist if I remove this:

    – The MW
    Nov 14 '18 at 10:36











  • ServletWebServerFactory implementation com.my.MyApplication$2 what does that class look like?

    – Darren Forsythe
    Nov 14 '18 at 10:37











  • @DarrenForsythe that is the TomcatServletWebServerFactory .

    – The MW
    Nov 14 '18 at 10:52











  • Have you tried to define bean TomcatServletWebServerFactoryCustomizer and call addConnectorCustomizers instead TomcatServletWebServerFactory?

    – Alexander Pankin
    Nov 14 '18 at 15:37
















1












1








1








In my spring boot 2.0 application, I have the main application listening on port 1234, I want to have the management server running on 1235.



So in my config file, I set:



management.server.port=1235



My server fails to start, with this error:




[ERROR] 2018-11-14 05:20:14.958 [main] SpringApplication - Application run failed
org.springframework.beans.FatalBeanException: ServletWebServerFactory implementation com.my.MyApplication$2 cannot be instantiated. To allow a separate management port to be used, a top-level class or static inner class should be used instead
at 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]
at 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-beans-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at 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]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) ~[spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775) [spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:316) [spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260) [spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248) [spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at com.my.MyApplication.main(EmsApplication.java:51) [main/:?]




If I remove this:



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

}


then it works.



How to solve this problem?



thanks!










share|improve this question
















In my spring boot 2.0 application, I have the main application listening on port 1234, I want to have the management server running on 1235.



So in my config file, I set:



management.server.port=1235



My server fails to start, with this error:




[ERROR] 2018-11-14 05:20:14.958 [main] SpringApplication - Application run failed
org.springframework.beans.FatalBeanException: ServletWebServerFactory implementation com.my.MyApplication$2 cannot be instantiated. To allow a separate management port to be used, a top-level class or static inner class should be used instead
at 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]
at 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-beans-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at 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]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) ~[spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775) [spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:316) [spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260) [spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248) [spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at com.my.MyApplication.main(EmsApplication.java:51) [main/:?]




If I remove this:



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

}


then it works.



How to solve this problem?



thanks!







spring spring-boot spring-boot-actuator






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 14 '18 at 11:59









Zain Farooq

2,0002928




2,0002928










asked Nov 14 '18 at 10:28









The MWThe MW

285




285













  • The problem doesn't exist if I remove this:

    – The MW
    Nov 14 '18 at 10:36











  • ServletWebServerFactory implementation com.my.MyApplication$2 what does that class look like?

    – Darren Forsythe
    Nov 14 '18 at 10:37











  • @DarrenForsythe that is the TomcatServletWebServerFactory .

    – The MW
    Nov 14 '18 at 10:52











  • Have you tried to define bean TomcatServletWebServerFactoryCustomizer and call addConnectorCustomizers instead TomcatServletWebServerFactory?

    – Alexander Pankin
    Nov 14 '18 at 15:37





















  • The problem doesn't exist if I remove this:

    – The MW
    Nov 14 '18 at 10:36











  • ServletWebServerFactory implementation com.my.MyApplication$2 what does that class look like?

    – Darren Forsythe
    Nov 14 '18 at 10:37











  • @DarrenForsythe that is the TomcatServletWebServerFactory .

    – The MW
    Nov 14 '18 at 10:52











  • Have you tried to define bean TomcatServletWebServerFactoryCustomizer and call addConnectorCustomizers instead TomcatServletWebServerFactory?

    – Alexander Pankin
    Nov 14 '18 at 15:37



















The problem doesn't exist if I remove this:

– The MW
Nov 14 '18 at 10:36





The problem doesn't exist if I remove this:

– The MW
Nov 14 '18 at 10:36













ServletWebServerFactory implementation com.my.MyApplication$2 what does that class look like?

– Darren Forsythe
Nov 14 '18 at 10:37





ServletWebServerFactory implementation com.my.MyApplication$2 what does that class look like?

– Darren Forsythe
Nov 14 '18 at 10:37













@DarrenForsythe that is the TomcatServletWebServerFactory .

– The MW
Nov 14 '18 at 10:52





@DarrenForsythe that is the TomcatServletWebServerFactory .

– The MW
Nov 14 '18 at 10:52













Have you tried to define bean TomcatServletWebServerFactoryCustomizer and call addConnectorCustomizers instead TomcatServletWebServerFactory?

– Alexander Pankin
Nov 14 '18 at 15:37







Have you tried to define bean TomcatServletWebServerFactoryCustomizer and call addConnectorCustomizers instead TomcatServletWebServerFactory?

– Alexander Pankin
Nov 14 '18 at 15:37














1 Answer
1






active

oldest

votes


















1














Your TomcatWebServerFactory sub-class is an anonymous inner-class. It needs to be a static inner-class or a top-level class so that it can be instantiated:



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

}


Alternatively, you could use a customizer instead of sub-classing TomcatServletWebServerFactory:



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





share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53298008%2fspring-boot-2-1-0-management-server-port-on-different-port%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    Your TomcatWebServerFactory sub-class is an anonymous inner-class. It needs to be a static inner-class or a top-level class so that it can be instantiated:



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

    }


    Alternatively, you could use a customizer instead of sub-classing TomcatServletWebServerFactory:



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





    share|improve this answer




























      1














      Your TomcatWebServerFactory sub-class is an anonymous inner-class. It needs to be a static inner-class or a top-level class so that it can be instantiated:



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

      }


      Alternatively, you could use a customizer instead of sub-classing TomcatServletWebServerFactory:



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





      share|improve this answer


























        1












        1








        1







        Your TomcatWebServerFactory sub-class is an anonymous inner-class. It needs to be a static inner-class or a top-level class so that it can be instantiated:



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

        }


        Alternatively, you could use a customizer instead of sub-classing TomcatServletWebServerFactory:



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





        share|improve this answer













        Your TomcatWebServerFactory sub-class is an anonymous inner-class. It needs to be a static inner-class or a top-level class so that it can be instantiated:



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

        }


        Alternatively, you could use a customizer instead of sub-classing TomcatServletWebServerFactory:



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






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 14 '18 at 17:24









        Andy WilkinsonAndy Wilkinson

        58.1k9139146




        58.1k9139146
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53298008%2fspring-boot-2-1-0-management-server-port-on-different-port%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Florida Star v. B. J. F.

            Danny Elfman

            Retrieve a Users Dashboard in Tumblr with R and TumblR. Oauth Issues