Tag: sticky session

在spring boot 2.0.0中设置jvmRoute

对于粘性会话,我需要设置嵌入式tomcat的jvmRoute。 实际上只有一个 System.setProperty(“jvmRoute”, “node1”); 是必需的,但我想设置一个via application.properties可配置属性。 我不知道如何以及何时使用@Value注释属性进行设置。 使用@PostConstruct,如此处所述,它不起作用(至少不在spring boot 2.0.0.RELEASE中) 我到目前为止找到的唯一方法是 @Component public class TomcatInitializer implements ApplicationListener { @Value(“${tomcat.jvmroute}”) private String jvmRoute; @Override public void onApplicationEvent(final ServletWebServerInitializedEvent event) { final WebServer ws = event.getApplicationContext().getWebServer(); if (ws instanceof TomcatWebServer) { final TomcatWebServer tws = (TomcatWebServer) ws; final Context context = (Context) tws.getTomcat().getHost().findChildren()[0]; context.getManager().getSessionIdGenerator().setJvmRoute(jvmRoute); } } } […]