All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cn.jiangzeyin.common.spring.TomcatInitBean Maven / Gradle / Ivy

There is a newer version: 1.1.11
Show newest version
package cn.jiangzeyin.common.spring;

import cn.jiangzeyin.CommonPropertiesFinal;
import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer;
import org.springframework.boot.web.servlet.ServletContextInitializer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.TimeUnit;

/**
 * Created by jiangzeyin on 2017/3/31.
 */
@Configuration
public class TomcatInitBean {

    /**
     * session 超时
     *
     * @return embedded
     */
    @Bean
    public EmbeddedServletContainerCustomizer containerCustomizer() {
        return container -> {
            Integer timout = SpringUtil.getEnvironment().getProperty(CommonPropertiesFinal.TOMCAT_SESSION_TIME_OUT, Integer.class);
            if (timout != null)
                container.setSessionTimeout(timout, TimeUnit.MINUTES);//单位为分钟
        };
    }

    @Bean
    public ServletContextInitializer servletContextInitializer() {
        return servletContext -> {
            String name = SpringUtil.getEnvironment().getProperty(CommonPropertiesFinal.TOMCAT_SESSION_COOKIE_NAME);
            if (name != null && name.length() > 0)
                servletContext.getSessionCookieConfig().setName(name);
        };
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy