복붙노트

[SPRING] TomcatEmbeddedServletContainerFactory가 봄 부팅 2에 없습니다.

SPRING

TomcatEmbeddedServletContainerFactory가 봄 부팅 2에 없습니다.

org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory를 사용하는 Spring Boot 응용 프로그램 버전 1.5.x가 있는데, Spring Boot 2로 마이그레이션하려고 시도하지만, 종속성이 있지만 응용 프로그램이 컴파일되지 않습니다. org.springframework.boot : spring-boot-starter-tomcat. 컴파일러는 아래 오류를 발행합니다.

error: package org.springframework.boot.context.embedded.tomcat

해결법

  1. ==============================

    1.스프링 부트 2.0.0.RELEASE에서는 다음 코드로 대체 할 수 있습니다 ::

    스프링 부트 2.0.0.RELEASE에서는 다음 코드로 대체 할 수 있습니다 ::

    @Bean
    public ServletWebServerFactory servletContainer() {
        TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory() {
            @Override
            protected void postProcessContext(Context context) {
                SecurityConstraint securityConstraint = new SecurityConstraint();
                securityConstraint.setUserConstraint("CONFIDENTIAL");
                SecurityCollection collection = new SecurityCollection();
                collection.addPattern("/*");
                securityConstraint.addCollection(collection);
                context.addConstraint(securityConstraint);
            }
        };
        tomcat.addAdditionalTomcatConnectors(redirectConnector());
        return tomcat;
    }
    
    private Connector redirectConnector() {
        Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
        connector.setScheme("http");
        connector.setPort(8080);
        connector.setSecure(false);
        connector.setRedirectPort(8443);
        return connector;
    }
    
  2. ==============================

    2.클래스가 제거되고 org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory로 대체되었습니다. 자세한 정보는 다음을 확인하십시오 : Spring-Boot-2.0-Migration-Guide,

    클래스가 제거되고 org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory로 대체되었습니다. 자세한 정보는 다음을 확인하십시오 : Spring-Boot-2.0-Migration-Guide,

    더 큰 요청을 보내야한다는 문제가 있었지만 기본 크기는 허용되었습니다.

    @Bean
        public TomcatServletWebServerFactory containerFactory() {
            return new TomcatServletWebServerFactory() {
                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);
                        logger.info("Set MaxSwallowSize "+ maxSize);
                    }
                }
            };
    
        }
    
  3. from https://stackoverflow.com/questions/47700115/tomcatembeddedservletcontainerfactory-is-missing-in-spring-boot-2 by cc-by-sa and MIT license