[英]How to remove the Ehcache WARN messages when using Hibernate
我有这个Ehcache XML配置:
<ehcache>
<defaultCache
maxElementsInMemory="10000"
eternal="false"
timeToIdleSeconds="120"
timeToLiveSeconds="120"
overflowToDisk="false"
diskSpoolBufferSizeMB="30"
diskPersistent="false"
diskExpiryThreadIntervalSeconds="120"
memoryStoreEvictionPolicy="LRU"
/>
</ehcache>
而且,我有一些实体包(大约150个)。 如果我在tomcat服务器上部署我的应用程序,日志中会有很多WARN消息:
2015-04-29 11:59:02,712 [RMI TCP连接(3)-127.0.0.1] WARN org.hibernate.cache.ehcache.AbstractEhcacheRegionFactory - HHH020003:无法找到名为[com.company的缓存的特定ehcache配置。 project.entity.package.MyEntity]; 使用默认值。
我可以为每个实体编写配置 -
<cache name="com.company.project.entity.package.MyEntity"
maxEntriesLocalHeap="50"
eternal="false"
overflowToDisk="false"
timeToLiveSeconds="120">
<persistence strategy="localTempSwap"/>
</cache>
但是这样,我的配置文件变得太大(1600行)。 我认为存在另一种方法来为每个实体设置默认配置并终止警告消息,但我不知道该怎么做。 如果有人知道,请帮忙。 非常感谢。
这是记录警告消息的Hibernate EHCache缓存区域代码:
private Ehcache getCache(String name) throws CacheException {
try {
Ehcache cache = manager.getEhcache( name );
if ( cache == null ) {
LOG.unableToFindEhCacheConfiguration( name );
manager.addCache( name );
cache = manager.getEhcache( name );
LOG.debug( "started EHCache region: " + name );
}
HibernateEhcacheUtils.validateEhcache( cache );
return cache;
}
catch (net.sf.ehcache.CacheException e) {
throw new CacheException( e );
}
}
如您所见,您有两种选择:
ehcache.xml
文件中声明缓存区域。 您将'org.hibernate.cache.ehcache.AbstractEhcacheRegionFactory'日志级别设置为ERROR:
对于Log4j2:
<Logger name="org.hibernate.cache.ehcache.AbstractEhcacheRegionFactory" level="error"> <AppenderRef ref="File"/> </Logger>
一种选择是创建一个CacheObject基本实体并将其配置为您的缓存对象。
不是最干净的解决方案,但会在不添加大量配置的情况下删除警告。
正如警告那样,个人警告我只是将其配置为不显示。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.