java - ehcache 在 Tomcat Docker 镜像中不工作

标签 java tomcat docker amazon-elastic-beanstalk ehcache

我得到了一个 Java 应用程序来进行容器化。

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

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

部署错误与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 版本不可用,则会出现此错误。

我已经检查了应用程序有效负载,正确的 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的名字。您的冲突来自于 ehcache-core-2.4.5.jarehcache-2.10.2.jar 在您的类路径中。

很可能第一个被第一个拾取,因此你得到这个无效的属性错误。您很可能必须删除 ehcache-core-2.4.5.jar 但这可能需要增加其他依赖项,尽管 Ehcache 始终试图在 2.x 系列中保持向后兼容性。

关于java - ehcache 在 Tomcat Docker 镜像中不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42143633/

相关文章:

java - 在Docker中构建Maven项目时,所有目标文件都是root的

docker - 服务无法启动虚拟机 'DockerDesktopVM',因为其中一个 Hyper-V 组件未运行

java - Esper 基于客户的查询非常适合多个客户

java - Log4j、maven tomcat7-maven-plugin、spring rest 服务

java - disableRegistry() 不存在 (org.apache.tomcat.util.modeler.Registry)

java - MySQL 数据库的 JDBC CommunicationsException

java - 一个接口(interface),其中所有方法具有多个实现类,每个实现类实现该接口(interface)中方法的子集

java - file.exists() 意外返回 false

java - getSource() 和 getActionCommand()

linux - 如何在 mosquitto Docker 容器中编辑 mosquitto.conf?