我还没有找到任何关于如何在使用带有 Spring Boot 的嵌入式 tomcat 时以编程方式设置 tomcat session 复制的指南。甚至很难找到“tomcat-catalina-ha”依赖项。
我有一个工作 Tomcat session 复制示例,在非嵌入式 Tomcat 上设置时可以工作,但将其转换为 Java 配置却不起作用。我研究了 Hazelcast,但我需要的一些选项需要企业许可证。我还被告知,在传统数据库中存储 session 不能很好地扩展。
我正在寻找使用嵌入式 tomcat 实现 Tomcat session 复制的指南或示例项目。除此之外,我很想知道为什么一开始就没有指南?
最佳答案
经过更多研究,我发现了这个 documentation :
The list listed here is the only place that configuration and how-to questions belong, ever.
浏览邮件列表存档,我找到了一个编程集群配置的示例:https://marc.info/?l=tomcat-user&m=160220406421937&w=2
它能够帮助我完成大部分工作,我一直通过以下方式在上下文中设置集群:
@Configuration
public class MyConfig implements WebServerFactoryCustomize<TomcatServletWebServerFactory> {
@Override
public void customize(TomcatServletWebServerFactory factory) {
factory.addContextCustomizers(context -> {
//cluster setup
SimpleTcpCluster simpleTcpCluster = new SimpleTcpCluster();
// order of your interceptors does matter fyi
// rest of setup details, very similar to mailing list archive
// Make sure the DeltaManager is created for me
context.setDistributable(true);
// The key point:
//context.setCluster(simpleTcpCluster);
// The fix instead of context.setCluster
// context.getParent() is an instance of StandardHost
// And if you are coping from a server.xml, it's also clear
// that the cluster element is set on the host
context.getParent().setCluster(simpleTcpCluster);
// Basically by setting it on the `host`, it allows the startup to
// recognize it early enough to start the cluster up.
});
}
当我在上下文中设置集群时,没有任何集群元素真正启动。
我还要指出的是,在调查此问题时,我发现了 article (2013) 展示了如何在使用嵌入式 tomcat 时加载 server.xml
,尽管我没有尝试过。
最后一点:我使用了 StaticMembershipService
与多播内容,或 StaticMembershipInterceptor
。
关于spring-boot - 如何使用 Spring Boot 嵌入式 tomcat 设置 Tomcat session 复制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75464308/