2

我正在尝试使用 Spring 配置文件(最终在 Tomcat 中使用)配置 JBossCache 的实例。我在网上没有看到任何示例,并试图找出示例 JBoss Microcontainer 格式和 Spring IoC 之间的映射。

有人有 JBoss Cache 的示例 Spring 配置吗?

4

1 回答 1

3

JBossCache(至少是 v3)非常吸引人的方面之一是其 API 主要由符合 JavaBean 的类组成。这使得它们很容易在 Spring 中连接起来。

JBoss MicroContainer 格式并没有做任何特别的事情,它都是 POJO 设置器和构造器注入。因此,与其尝试将 JBossMC 语法转换为 Spring,不如直接查看类本身。JBossCache 文档还包含大量编程配置的示例。

这是我的应用程序中使用 Spring 3@Bean样式配置的示例。翻译成 XML 语法很容易,但这要好得多:

@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);
}
于 2010-12-21T19:32:23.637 回答