Created
August 21, 2012 14:43
-
-
Save pledbrook/3416150 to your computer and use it in GitHub Desktop.
Environment-specific cache managers in Spring
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.example.config; | |
import org.springframework.cache.concurrent.ConcurrentMapCacheManager | |
@Configuration | |
public class ApplicationConfig { | |
@Bean public ConcurrentMapCacheManager cacheManager() { | |
return new ConcurrentMapCacheManager(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.example.config; | |
import org.springframework.data.redis.cache.RedisCacheManager; | |
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory; | |
import org.springframework.data.redis.core.RedisTemplate; | |
@Configuration | |
@Profile("cloud") | |
public class CloudApplicationConfig { | |
@Bean public JedisConnectionFactory jedisConnectionFactory() { | |
JedisConnectionFactory factory = new JedisConnectionFactory(); | |
factory.setUsePool(true); | |
return factory; | |
} | |
@Bean public RedisTemplate redisTemplate() { | |
return new RedisTemplate(jedisConnectionFactory()); | |
} | |
@Bean public RedisCacheManager cacheManager() { | |
return new RedisCacheManager(redisTemplate()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<web-app> | |
<context-param> | |
<param-name>contextClass</param-name> | |
<param-value> | |
org.springframework.web.context.support.AnnotationConfigWebApplicationContext | |
</param-value> | |
</context-param> | |
<context-param> | |
<param-name>contextConfigLocation</param-name> | |
<param-value>org.example.config.ApplicationConfig,org.example.config.CloudApplicationConfig</param-value> | |
</context-param> | |
<listener> | |
<listener-class> | |
org.springframework.web.context.ContextLoaderListener | |
</listener-class> | |
</listener> | |
<servlet> | |
<servlet-name>sampleServlet</servlet-name> | |
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> | |
<load-on-startup>1</load-on-startup> | |
</servlet> | |
... | |
</web-app> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment