简体   繁体   English

Mod_Cluster LifecycleListeners Spring Boot

[英]Mod_Cluster LifecycleListeners Spring Boot

I'm migrating my project Spring to Spring Boot.我正在将我的项目 Spring 迁移到 Spring Boot。 But I'm faced with a problem, we have a reverse proxy using apache2 and mod_cluster.但是我遇到了一个问题,我们有一个使用 apache2 和 mod_cluster 的反向代理。 In actual version we declare a Listerner in the server.xml.在实际版本中,我们在 server.xml 中声明了一个 Listerner。

<Listener className="org.jboss.modcluster.container.catalina.standalone.ModClusterListener" advertise="false" proxyList="${proxyList}" />

I put it like a Spring boot application.我把它当作一个 Spring 启动应用程序。

private Connector ajpConnector() {
    Connector connector = new Connector("AJP/1.3");
    connector.setPort(8009);
    connector.setRedirectPort(8443);
    return connector;
}


private ModClusterListener modCluster() {
    ModClusterListener modClusterListener = new ModClusterListener();
    modClusterListener.setAdvertise(false);
    modClusterListener.setProxyURL(proxyUrl);

    return modClusterListener;
}

@Bean
public WebServerFactoryCustomizer<TomcatServletWebServerFactory> servletContainer() {
    return server -> {
        if (server != null) {
            server.addContextLifecycleListeners(modCluster());
            server.addAdditionalTomcatConnectors(ajpConnector());
        }
    };
}

But it don't work, the ModClusterListener want a LifecycleEvent of type Sever, but it never happen.但它不起作用,ModClusterListener 想要一个 Sever 类型的 LifecycleEvent,但它永远不会发生。 Can anyone help me?谁能帮我?

I posted the question on Gitter and Andy Wilkinson helped me.我在 Gitter 上发布了这个问题,Andy Wilkinson 帮助了我。

"From what you've said, it sounds like ModClusterListener needs to be added to Tomcat's Server but the method you've used will add it to the Context. You could use a context customizer and navigate up from the Context till you find the Server or you could use a TomcatServletWebServerFactory sub-class instead:" “从你所说的来看,听起来像 ModClusterListener 需要添加到 Tomcat 的服务器,但你使用的方法会将它添加到上下文中。你可以使用上下文定制器并从上下文向上导航,直到找到服务器或者您可以改用 TomcatServletWebServerFactory 子类:”

@Bean
public TomcatServletWebServerFactory tomcatFactory() {
    return new TomcatServletWebServerFactory() {

        @Override
        protected TomcatWebServer getTomcatWebServer(Tomcat tomcat) {
            tomcat.getServer().addLifecycleListener(modCluster());
            return new TomcatWebServer(tomcat);
        }

    };
}

It worked for me!它对我有用!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM