0

我是 JBossCache 的新手。阅读用户文档,它说可以将侦听器添加到使用的 Eviction 类中,但我无法找到如何将一个侦听器添加到配置文件,或者应该如何添加。

我尝试使用@NodeEvicted 方法添加@CacheListener,但该方法

@CacheListener
public class EvictionListener {

    @NodeEvicted
    public void nodeEvicted(NodeEvent ne) {
        System.out.println("Se borro el nodo");
    }
}

并将其添加到缓存实例

CacheFactory factory = new DefaultCacheFactory();
this.cache = factory.createCache();

EvictionListener listener = new EvictionListener();
this.cache.create();
this.cache.addCacheListener(listener);

但系统输出未执行。为了测试它,我只是运行一个简单的 Main 值。这是我正在使用的配置值:

<jbosscache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="urn:jboss:jbosscache-core:config:3.2">


    <transaction transactionManagerLookupClass="org.jboss.cache.transaction.GenericTransactionManagerLookup"/>


    <eviction wakeUpInterval="20">
        <default algorithmClass="org.jboss.cache.eviction.FIFOAlgorithm" wakeUpInterval="20">
            <property name="maxNodes" value="20" />         
        </default>           
    </eviction>

</jbosscache>
4

1 回答 1

0

问题已解决,因为我没有读取 XML 配置文件。

我失踪了:

factory.createCache(file);
于 2011-10-12T18:45:34.187 回答