2

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 Answer 1

3

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.