在应用程序的配置中声明 Bean:ServletContextInitializer
@Bean
public ServletContextInitializer servletContextInitializer() {
return new ServletContextInitializer() {
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
servletContext.getSessionCookieConfig().setName("yourCookieName");
}
};
}
或者,您的应用程序类本身可以实现:ServletContextInitializer
@Configuration
@EnableAutoConfiguration
@ComponentScan
public class Application implements ServletContextInitializer {
public static void main(String[] args) throws Exception {
SpringApplication.run(Application.class, args);
}
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
servletContext.getSessionCookieConfig().setName("yourCookieName");
}
}