Vitor Gomes Miranda
Vitor Gomes Miranda

Reputation: 33

Memcached with Spring Boot

I have an application that uses spring-boot, and must work in parallel with other legacy application .

For this I'll use memcached for session storage, just that I can't find way to use the memcached in my application with spring-boot.

Someone please could tell me what I might add in the property file that corresponds to this change in context.xml

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

I'm using the Tomcat 7

Sorry for my english.

Thanks.

Upvotes: 3

Views: 4997

Answers (1)

Andy Wilkinson
Andy Wilkinson

Reputation: 116091

Spring Boot doesn't provide any out-of-the-box support for using memcached for session storage so it cannot be configured via application.properties.

You can, however, configure it programatically by customising the embedded Tomcat instance. The following Java configuration is equivalent to the 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);
        }

    };
}

Upvotes: 11

Related Questions