我正在尝试在我的Android应用中使用ehcache。它在第一行失败了。所以这与错误的缓存配置无关。我打算以编程方式配置缓存,所以我没有任何配置文件。我所做的就是添加ehcache作为依赖项并尝试调用下面的方法。使用ehcache 2.10.2
CacheManager singletonManager = CacheManager.create();
堆栈跟踪:
W/System.err: SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
W/System.err: SLF4J: Defaulting to no-operation (NOP) logger implementation
W/System.err: SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
E/AndroidRuntime: FATAL EXCEPTION: Thread-158
Process: test.app, PID: 7275
java.lang.ExceptionInInitializerError
at net.sf.ehcache.config.Configuration.<init>(Configuration.java:208)
at net.sf.ehcache.config.ConfigurationFactory.parseConfiguration(ConfigurationFactory.java:152)
at net.sf.ehcache.config.ConfigurationFactory.parseConfiguration(ConfigurationFactory.java:103)
at net.sf.ehcache.config.ConfigurationFactory.parseConfiguration(ConfigurationFactory.java:140)
at net.sf.ehcache.CacheManager.newInstance(CacheManager.java:892)
at net.sf.ehcache.CacheManager.create(CacheManager.java:873)
at test.app.MyCache.setup(MyCache.java:20)
Caused by: java.lang.NullPointerException: parentLoader == null && !nullAllowed
at java.lang.ClassLoader.<init>(ClassLoader.java:210)
at java.lang.ClassLoader.<init>(ClassLoader.java:202)
at net.sf.ehcache.EhcacheDefaultClassLoader.<init>(EhcacheDefaultClassLoader.java:35)
at net.sf.ehcache.EhcacheDefaultClassLoader.<clinit>(EhcacheDefaultClassLoader.java:26)
at net.sf.ehcache.config.Configuration.<init>(Configuration.java:208)
at net.sf.ehcache.config.ConfigurationFactory.parseConfiguration(ConfigurationFactory.java:152)
at net.sf.ehcache.config.ConfigurationFactory.parseConfiguration(ConfigurationFactory.java:103)
at net.sf.ehcache.config.ConfigurationFactory.parseConfiguration(ConfigurationFactory.java:140)
at net.sf.ehcache.CacheManager.newInstance(CacheManager.java:892)
at net.sf.ehcache.CacheManager.create(CacheManager.java:873)
at test.app.MyCache.setup(MyCache.java:20)
答案 0 :(得分:0)
试试这个:
create()
不是:Failed to load class "org.slf4j.impl.StaticLoggerBinder".
修改强>
你是对的。仍然是同样的问题。我试过了
<defaultCache
maxElementsInMemory="10000"
eternal="false"
timeToIdleSeconds="120"
timeToLiveSeconds="120"
overflowToDisk="true"
maxElementsOnDisk="10000000"
diskPersistent="false"
diskExpiryThreadIntervalSeconds="120"
memoryStoreEvictionPolicy="LRU"
/>
这意味着没有SLF4J绑定。
在类路径上放置一个(也是唯一一个)slf4j-nop.jar,slf4j-simple.jar,slf4j-log4j12.jar,slf4j-jdk14.jar或logback-classic.jar应解决问题
这里是 link 确保你只添加一个罐子
编辑2 :
如果要删除配置警告,请添加ehcache.xml文件。这是一个例子:
CREATE USER 'new_user'@'%' IDENTIFIED BY 'new_user_password';
尝试一下。