Skip to content

Commit

Permalink
支持对tomcat进行配置 (#839)
Browse files Browse the repository at this point in the history
Co-authored-by: 巨鹿 <yanwen@cai-inc.com>
  • Loading branch information
qq290584697 and 巨鹿 committed Jan 26, 2024
1 parent ca0f15f commit 1b2ac68
Showing 1 changed file with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,22 @@
import com.alipay.sofa.ark.springboot.web.ArkTomcatServletWebServerFactory;
import org.apache.catalina.startup.Tomcat;
import org.apache.coyote.UpgradeProtocol;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.SearchStrategy;
import org.springframework.boot.autoconfigure.web.servlet.ServletWebServerFactoryAutoConfiguration;
import org.springframework.boot.web.embedded.tomcat.TomcatConnectorCustomizer;
import org.springframework.boot.web.embedded.tomcat.TomcatContextCustomizer;
import org.springframework.boot.web.embedded.tomcat.TomcatProtocolHandlerCustomizer;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.boot.web.servlet.server.ServletWebServerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.servlet.Servlet;
import java.util.stream.Collectors;

/**
* @author qilong.zql
Expand All @@ -50,8 +55,17 @@ public static class EmbeddedArkTomcat {

@Bean
@ConditionalOnMissingBean(ArkTomcatServletWebServerFactory.class)
public TomcatServletWebServerFactory tomcatServletWebServerFactory() {
return new ArkTomcatServletWebServerFactory();
public TomcatServletWebServerFactory tomcatServletWebServerFactory(ObjectProvider<TomcatConnectorCustomizer> connectorCustomizers,
ObjectProvider<TomcatContextCustomizer> contextCustomizers,
ObjectProvider<TomcatProtocolHandlerCustomizer<?>> protocolHandlerCustomizers) {
ArkTomcatServletWebServerFactory factory = new ArkTomcatServletWebServerFactory();
factory.getTomcatConnectorCustomizers().addAll(
connectorCustomizers.orderedStream().collect(Collectors.toList()));
factory.getTomcatContextCustomizers().addAll(
contextCustomizers.orderedStream().collect(Collectors.toList()));
factory.getTomcatProtocolHandlerCustomizers().addAll(
protocolHandlerCustomizers.orderedStream().collect(Collectors.toList()));
return factory;
}

}
Expand Down

0 comments on commit 1b2ac68

Please sign in to comment.