java.lang.NullPointerException Hibernate used with Ehcache

淺唱寂寞╮ 提交于 2019-12-06 03:42:07

That's allright. You do not have to explicitly specify value for property "net.sf.ehcache.configurationResourceName" if the resource is named ehcache.xml and placed in a class path. You can chose this option when you have multiple cache managers.

Or you can just move all your resource files from lib to a directory like WEB-INF/resources so that it becomes easier to reference it under classpath.

Ehcache looks for a file called ehcache.xml in the top level of the classpath. Failing that it looks for ehcache-failsafe.xml in the classpath. ehcache-failsafe.xml is packaged in the Ehcache jar and should always be found.

Finally I found the reason why my code didn't work. Thanks for Vinodn for your suggestion.

config.getDefaultCacheConfiguration().isTerracottaClustered() 

Actually, I didn't configure defaultCache tag in my ehcache-entity.xml, as a result

config.getDefaultCacheConfiguration()

return null. So adding defaultCache solved the problem.

Place ehcache-entity.xml in your classpath to be loaded by your hibernate configuration.

adding defaultCache configuration in ehcache.xml help me too.

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