我正在尝试使用 Spring 配置文件配置 JBossCache 的实例(最终在 Tomcat 中使用)。我没有在网上看到任何示例,也没有尝试找出示例 JBoss Microcontainer 格式和 Spring IoC 之间的映射。
有人有 JBoss Cache 的 Spring 配置示例吗?
最佳答案
JBossCache(至少是 v3)非常吸引人的方面之一是 API 主要由符合 JavaBean 的类组成。这使得它们在 Spring 中非常容易连接。
JBoss MicroContainer 格式没有做任何特殊的事情,它只是 POJO setter 和构造函数注入(inject)。因此,与其尝试将 JBossMC 语法转换为 Spring,不如直接查看类本身。 JBossCache 文档还包含大量编程配置示例。
这是我的应用程序中使用 Spring 3 @Bean
样式配置的示例。转换成 XML synyax 很容易,但是这样要好得多:
@Bean(destroyMethod="stop")
public <K,V> Cache<K, V> csiCache() {
org.jboss.cache.config.Configuration cacheConfiguration = new org.jboss.cache.config.Configuration();
cacheConfiguration.setCacheMode(CacheMode.REPL_ASYNC);
cacheConfiguration.setTransactionManagerLookupClass(JBossTransactionManagerLookup.class.getName());
cacheConfiguration.setClusterName(cacheClusterName);
cacheConfiguration.setEvictionConfig(new EvictionConfig(new EvictionRegionConfig(
Fqn.ROOT, new ExpirationAlgorithmConfig()
)));
return new DefaultCacheFactory<K, V>().createCache(cacheConfiguration, true);
}
关于JBossCache 的 Spring 配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4502992/