Memcached with Spring Boot

I have an application that uses spring-boot and needs to run in parallel with another legacy application.

For this I will be using memcached to store sessions, I just cannot find a way to use memcached in my application using spring-boot.

Someone please tell me what I can add in the properties file that corresponds to this change in the context.xml

<Manager 
    className="de.javakaffee.web.msm.MemcachedBackupSessionManager"
    memcachedNodes="n1:servidor-memcached:11211"
    requestUriIgnorePattern=".*\.(ico|png|gif|jpg|css|js)$"
/>

      

I am using Tomcat 7

Sorry for my English.

Thank.

+3


source to share


1 answer


Spring Boot does not provide any built-in support for using memcached to store a session, so it cannot be configured with application.properties

.

You can, however, configure it programmatically by configuring an embedded Tomcat instance. The following Java configuration is equivalent to Tomcat context.xml

in the question:



@Bean
public EmbeddedServletContainerFactory tomcat() {
    return new TomcatEmbeddedServletContainerFactory() {

        @Override
        protected void postProcessContext(Context context) {
            MemcachedBackupSessionManager manager = new MemcachedBackupSessionManager();
            manager.setMemcachedNodes("n1:servidor-memcached:11211");
            manager.setRequestUriIgnorePattern(".*\\.(ico|png|gif|jpg|css|js)$");
            context.setManager(manager);
        }

    };
}

      

+9


source







All Articles