about 2 months ago

有些舊系統前端是傳統 apache + ajp13 接後面 Tomcat 服務
這個時候可以讓 springboot 也接收這種 protocol

EmbeddedTomcatConfiguration.java
/**
 * 配置 ajp 端口 (預設的http還在喔)
 * Created by samzh on 2017/3/14.
 */
@Configuration
public class EmbeddedTomcatConfiguration {

    @Value("${server.additionalPorts:null}")
    private String additionalPorts;

    @Bean
    public EmbeddedServletContainerFactory servletContainer() {
        TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory();
        Connector[] additionalConnectors = this.additionalConnector();
        if (additionalConnectors != null && additionalConnectors.length > 0) {
            tomcat.addAdditionalTomcatConnectors(additionalConnectors);
        }
        return tomcat;
    }

    private Connector[] additionalConnector() {
        if (StringUtils.isBlank(this.additionalPorts)) {
            return null;
        }
        //Set<String> defaultPorts = Sets.new HashSet(this.serverPort, this.managementPort);

        String[] ports = this.additionalPorts.split(",");
        List<Connector> result = new ArrayList<>();
        for (String port : ports) {
            Connector connector = new Connector("org.apache.coyote.ajp.AjpNioProtocol");
            connector.setScheme("http");
            connector.setPort(Integer.valueOf(port));
            result.add(connector);
        }
        return result.toArray(new Connector[]{});
    }
}
← Ubuntu 16.04.2 install VPN use shadowsocks SpringBootAdmin add Line push message →
 
comments powered by Disqus