2017-02-09 144 views
0

我已经给了一个Java应用程序来containerise。ehcache在Tomcat中不工作Docker镜像

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

但是,应用程序无法部署到我的Docker映像中,该映像是通过RPM安装的OpenJDK8和Tomcat8的Amazon Linux基础映像构建的。

的部署错误涉及到的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版本之间的配置不匹配这个错误通常出现,即maxEntriesLocalHeap在2.10版本推出,如果版本2.10不可用,则会发生此错误。

我已经在应用有效载荷检查,正确的罐子可用:

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的旧版本,但我看不到如何在一个香草的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> 

任何援助将不胜感激。

回答

1

Ehcache在历史过程中改变了罐子的名称。您的冲突来自您的类路径中有ehcache-core-2.4.5.jarehcache-2.10.2.jar

最有可能的第一个被挑选出来,因此你得到这个无效的属性错误。尽管Ehcache总是试图保持2.x行的向后兼容性,但您很可能不得不删除ehcache-core-2.4.5.jar,但可能需要冲突其他依赖项。

+0

答案是正确的。作为一个附注,如果我是你,我会把'updateCheck'设为false。 – Henri

+0

有道理,但我很好奇为什么这不是ElasticBeanstalk实例中的问题,而是Docker容器中的一个问题。 –