ehcache不能在Tomcat Docker镜像中工作

我有一个Java应用程序containerise。

该应用程序当前正在Tomcat8 JRE8 AWS Elasticbeanstalk实例上运行。

但是,应用程序无法在我的Docker镜像中部署,该镜像是通过安装有OpenJDK8和Tomcat8的Amazon Linux基础镜像构build的。

部署错误与Ehcache相关:

Error creating bean with name 'getEhcache' defined in *****: Invocation of init method failed; nested exception is net.sf.ehcache.CacheException: Error configuring from input stream. Initial cause was null:16: Element <cache> does not allow attribute "maxEntriesLocalHeap". 

我明白,当Ehcache和正在使用的Ehcache版本之间存在configuration不匹配时,通常会出现此错误,即版本2.10中引入了maxEntriesLocalHeap,如果版本2.10不可用,则会发生此错误。

我检查了应用程序的有效载荷,并提供正确的jar:

 bash-4.2# pwd /var/lib/tomcat8/webapps/ROOT/WEB-INF/lib bash-4.2# ls -la ehcache-* -rw-rw-r-- 1 root root 8914463 Jan 24 12:27 ehcache-2.10.2.jar -rw-rw-r-- 1 root root 1006074 Jan 24 12:27 ehcache-core-2.4.5.jar -rw-rw-r-- 1 root root 124522 Jan 24 12:27 ehcache-spring-annotations-1.2.0.jar 

开发人员告诉我,应用程序正在拾取一个老版本的Ehcache,但我不明白在一个vanilla Docker镜像中这是如何实现的。 我认为这是一个虚假的错误,是由运行时在Docker容器中的权限或文件系统访问所产生的。

随应用程序提供的ehcache.xml文件是:

 <ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="ehcache.xsd" updateCheck="true" monitoring="autodetect" dynamicConfig="true"> <diskStore path="java.io.tmpdir"/> <cache name="messageCache" maxEntriesLocalHeap="10000" maxEntriesLocalDisk="1000" eternal="false" diskSpoolBufferSizeMB="20" timeToIdleSeconds="43200" timeToLiveSeconds="43200" memoryStoreEvictionPolicy="LFU" transactionalMode="off"> <persistence strategy="localTempSwap"/> </cache> 

任何援助将不胜感激。

Ehcache已经在历史的进程中改变了jar子的名字。 你的冲突来自你的类path中的ehcache-core-2.4.5.jarehcache-2.10.2.jar

最有可能的第一个是先拿起来,因此你得到这个无效的属性错误。 尽pipeEhcache总是试图保持2.x行的向后兼容性,但很可能必须删除ehcache-core-2.4.5.jar但可能需要ehcache-core-2.4.5.jar其他依赖项。