Spring configuration for JBossCache

限于喜欢 提交于 2019-12-11 02:52:12

问题


I'm trying to configure an instance of JBossCache using a Spring config file (for eventual use in Tomcat). I don't see any examples online and trying to figure out the mapping between the sample JBoss Microcontainer format and Spring IoC.

Does anyone have any example Spring configs for JBoss Cache?


回答1:


One of the very appealing aspects of JBossCache (v3, at any rate) is that the API consists mainly of JavaBean-compliant classes. This makes them very easy to wire up in Spring.

The JBoss MicroContainer format isn't doing anything special with it, it's all POJO setter and constructor injection. So, rather than trying to translate JBossMC syntax into Spring, just look directly at the classes themselves. The JBossCache docs also contain plenty examples of programmatic configuration.

Here's an example from my app that uses Spring 3 @Bean-style config. It's easy enough to translate into XML synyax, but this is much nicer:

@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);
}


来源:https://stackoverflow.com/questions/4502992/spring-configuration-for-jbosscache

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!