如何解决 TomEE 8.x、Hibernate 5.4 和 Java 8 的 ASM 问题?

Posted

技术标签:

【中文标题】如何解决 TomEE 8.x、Hibernate 5.4 和 Java 8 的 ASM 问题?【英文标题】:How to cure ASM issues with TomEE 8.x, Hibernate 5.4 and Java 8? 【发布时间】:2020-05-04 22:11:17 【问题描述】:

根据此页面,TomEE 8.0 与 Java 8 兼容:http://tomee.apache.org/master/docs/java-compatibility.html

但是,我在使用 TomEE 和使用 java 8 的 Hibernate 设置项目时遇到了一些问题。

我从 Maven 原型 org.apache.openejb.maven:tomee-webapp-archetype 1.7.1 版创建一个项目。我的项目 SDK 是一个简单的 JDK 1.8.0_221。

一切都很顺利。运行 mvn packagemvn tomee:run 会启动一个运行良好的示例应用程序。

现在我转到我的 pom.xml 文件并添加 Hibernate 依赖项:

<dependency>
  <groupId>org.hibernate</groupId>
  <artifactId>hibernate-core</artifactId>
  <version>5.4.14.Final</version>
</dependency>

无需对项目进行更多修改。 mvn package 仍然可以正常工作。但是在启动应用程序时,我得到以下信息:

[INFO] Scanning for projects...
[INFO] 
[INFO] -----------------------< org.example:TomEETest >------------------------
[INFO] Building TomEETest TomEE Webapp 1.0-SNAPSHOT
[INFO] --------------------------------[ war ]---------------------------------
[INFO] 
[INFO] --- tomee-maven-plugin:1.7.1:run (default-cli) @ TomEETest ---
[INFO] TomEE was unzipped in '/Users/bcassistat/IdeaProjetcs/TomEETest/target/apache-tomee'
[INFO] Removed not mandatory default webapps
[INFO] Installed '/Users/bcassistat/IdeaProjetcs/TomEETest/target/TomEETest-1.0-SNAPSHOT.war' in /Users/bcassistat/IdeaProjetcs/TomEETest/target/apache-tomee/webapps/ROOT.war
[INFO] Running 'org.apache.openejb.maven.plugin.run'. Configured TomEE in plugin is localhost:8080 (plugin shutdown port is 8005 and https port is 8443)
Started server process on port: 8080
May 04, 2020 5:47:47 PM org.apache.catalina.core.AprLifecycleListener init
INFOS: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /Users/bcassistat/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:.
May 04, 2020 5:47:47 PM org.apache.coyote.AbstractProtocol init
INFOS: Initializing ProtocolHandler ["http-bio-8080"]
May 04, 2020 5:47:47 PM org.apache.coyote.AbstractProtocol init
INFOS: Initializing ProtocolHandler ["ajp-bio-8009"]
May 04, 2020 5:47:48 PM org.apache.openejb.util.OptionsLog info
INFOS: Using 'tomee.remote.support=true'
May 04, 2020 5:47:48 PM org.apache.openejb.util.OptionsLog info
INFOS: Using 'openejb.jdbc.datasource-creator=org.apache.tomee.jdbc.TomEEDataSourceCreator'
May 04, 2020 5:47:48 PM org.apache.openejb.OpenEJB$Instance <init>
INFOS: ********************************************************************************
May 04, 2020 5:47:48 PM org.apache.openejb.OpenEJB$Instance <init>
INFOS: OpenEJB http://openejb.apache.org/
May 04, 2020 5:47:48 PM org.apache.openejb.OpenEJB$Instance <init>
INFOS: Startup: Mon May 04 17:47:48 EDT 2020
May 04, 2020 5:47:48 PM org.apache.openejb.OpenEJB$Instance <init>
INFOS: Copyright 1999-2013 (C) Apache OpenEJB Project, All Rights Reserved.
May 04, 2020 5:47:48 PM org.apache.openejb.OpenEJB$Instance <init>
INFOS: Version: 4.7.1
May 04, 2020 5:47:48 PM org.apache.openejb.OpenEJB$Instance <init>
INFOS: Build date: 20140912
May 04, 2020 5:47:48 PM org.apache.openejb.OpenEJB$Instance <init>
INFOS: Build time: 01:43
May 04, 2020 5:47:48 PM org.apache.openejb.OpenEJB$Instance <init>
INFOS: ********************************************************************************
May 04, 2020 5:47:48 PM org.apache.openejb.OpenEJB$Instance <init>
INFOS: openejb.home = /Users/bcassistat/IdeaProjetcs/TomEETest/target/apache-tomee
May 04, 2020 5:47:48 PM org.apache.openejb.OpenEJB$Instance <init>
INFOS: openejb.base = /Users/bcassistat/IdeaProjetcs/TomEETest/target/apache-tomee
May 04, 2020 5:47:48 PM org.apache.openejb.cdi.CdiBuilder initializeOWB
INFOS: Created new singletonService org.apache.openejb.cdi.ThreadSingletonServiceImpl@587c290d
May 04, 2020 5:47:48 PM org.apache.openejb.cdi.CdiBuilder initializeOWB
INFOS: Succeeded in installing singleton service
May 04, 2020 5:47:48 PM org.apache.openejb.config.ConfigurationFactory init
INFOS: openejb configuration file is '/Users/bcassistat/IdeaProjetcs/TomEETest/target/apache-tomee/conf/tomee.xml'
[INFO] Waiting for command: [quit, exit, reload]
May 04, 2020 5:47:48 PM org.apache.openejb.config.ConfigurationFactory configureService
INFOS: Configuring Service(id=Tomcat Security Service, type=SecurityService, provider-id=Tomcat Security Service)
May 04, 2020 5:47:48 PM org.apache.openejb.config.ConfigurationFactory configureService
INFOS: Configuring Service(id=Default Transaction Manager, type=TransactionManager, provider-id=Default Transaction Manager)
May 04, 2020 5:47:48 PM org.apache.openejb.util.OptionsLog info
INFOS: Using 'openejb.system.apps=false'
May 04, 2020 5:47:48 PM org.apache.openejb.util.OptionsLog info
INFOS: Using 'openejb.deployments.classpath=false'
May 04, 2020 5:47:48 PM org.apache.openejb.assembler.classic.Assembler createRecipe
INFOS: Creating TransactionManager(id=Default Transaction Manager)
May 04, 2020 5:47:49 PM org.apache.openejb.assembler.classic.Assembler createRecipe
INFOS: Creating SecurityService(id=Tomcat Security Service)
May 04, 2020 5:47:49 PM org.apache.openejb.server.SimpleServiceManager start
INFOS:   ** Bound Services **
May 04, 2020 5:47:49 PM org.apache.openejb.server.SimpleServiceManager printRow
INFOS:   NAME                 IP              PORT  
May 04, 2020 5:47:49 PM org.apache.openejb.server.SimpleServiceManager start
INFOS: -------
May 04, 2020 5:47:49 PM org.apache.openejb.server.SimpleServiceManager start
INFOS: Ready!
May 04, 2020 5:47:49 PM org.apache.catalina.startup.Catalina load
INFOS: Initialization processed in 2002 ms
May 04, 2020 5:47:49 PM org.apache.tomee.catalina.OpenEJBNamingContextListener bindResource
INFOS: Importing a Tomcat Resource with id 'UserDatabase' of type 'org.apache.catalina.UserDatabase'.
May 04, 2020 5:47:49 PM org.apache.openejb.assembler.classic.Assembler createRecipe
INFOS: Creating Resource(id=UserDatabase)
May 04, 2020 5:47:49 PM org.apache.catalina.core.StandardService startInternal
INFOS: Démarrage du service Catalina
May 04, 2020 5:47:49 PM org.apache.catalina.core.StandardEngine startInternal
INFOS: Starting Servlet Engine: Apache Tomcat (TomEE)/7.0.55 (1.7.1)
May 04, 2020 5:47:49 PM org.apache.catalina.startup.HostConfig deployWAR
INFOS: Déploiement de l'archive /Users/bcassistat/IdeaProjetcs/TomEETest/target/apache-tomee/webapps/ROOT.war de l'application web
May 04, 2020 5:47:49 PM org.apache.tomee.catalina.TomcatWebAppBuilder init
INFOS: ------------------------- localhost -> /
May 04, 2020 5:47:49 PM org.apache.openejb.util.JarExtractor extract
INFOS: Extracting jar: /Users/bcassistat/IdeaProjetcs/TomEETest/target/apache-tomee/webapps/ROOT.war
May 04, 2020 5:47:49 PM org.apache.openejb.util.JarExtractor extract
INFOS: Extracted path: /Users/bcassistat/IdeaProjetcs/TomEETest/target/apache-tomee/webapps/ROOT
May 04, 2020 5:47:49 PM org.apache.openejb.util.OptionsLog info
INFOS: Using 'openejb.session.manager=org.apache.tomee.catalina.session.QuickSessionManager'
May 04, 2020 5:47:49 PM org.apache.tomee.catalina.TomEEClassLoaderEnricher validateJarFile
AVERTISSEMENT: jar '/Users/bcassistat/IdeaProjetcs/TomEETest/target/apache-tomee/webapps/ROOT/WEB-INF/lib/javax.persistence-api-2.2.jar' contains offending class: javax.persistence.Entity. It will be ignored.
May 04, 2020 5:47:49 PM org.apache.tomee.catalina.TomEEClassLoaderEnricher validateJarFile
AVERTISSEMENT: jar '/Users/bcassistat/IdeaProjetcs/TomEETest/target/apache-tomee/webapps/ROOT/WEB-INF/lib/jboss-transaction-api_1.2_spec-1.1.1.Final.jar' contains offending class: javax.transaction.Transaction. It will be ignored.
May 04, 2020 5:47:49 PM org.apache.catalina.core.ContainerBase addChildInternal
GRAVE: ContainerBase.addChild: start: 
org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[]]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:649)
    at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:1083)
    at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1880)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
Caused by: org.apache.tomee.catalina.TomEERuntimeException: org.apache.openejb.OpenEJBException: Unable to create annotation scanner for web module : null
    at org.apache.tomee.catalina.TomcatWebAppBuilder.loadApplication(TomcatWebAppBuilder.java:2150)
    at org.apache.tomee.catalina.TomcatWebAppBuilder.startInternal(TomcatWebAppBuilder.java:1134)
    at org.apache.tomee.catalina.TomcatWebAppBuilder.configureStart(TomcatWebAppBuilder.java:1087)
    at org.apache.tomee.catalina.GlobalListenerSupport.lifecycleEvent(GlobalListenerSupport.java:130)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
    at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5378)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    ... 10 more
Caused by: org.apache.openejb.OpenEJBException: Unable to create annotation scanner for web module : null
    at org.apache.openejb.config.DeploymentLoader.addWebModule(DeploymentLoader.java:844)
    at org.apache.openejb.config.DeploymentLoader.load(DeploymentLoader.java:216)
    at org.apache.tomee.catalina.TomcatWebAppBuilder.loadApplication(TomcatWebAppBuilder.java:2148)
    ... 17 more
Caused by: java.lang.IllegalArgumentException
    at org.apache.xbean.asm5.ClassReader.<init>(Unknown Source)
    at org.apache.xbean.asm5.ClassReader.<init>(Unknown Source)
    at org.apache.xbean.asm5.ClassReader.<init>(Unknown Source)
    at org.apache.xbean.finder.AnnotationFinder.readClassDef(AnnotationFinder.java:1148)
    at org.apache.xbean.finder.AnnotationFinder.<init>(AnnotationFinder.java:139)
    at org.apache.xbean.finder.AnnotationFinder.<init>(AnnotationFinder.java:152)
    at org.apache.openejb.config.FinderFactory$OpenEJBAnnotationFinder.<init>(FinderFactory.java:514)
    at org.apache.openejb.config.FinderFactory.newFinder(FinderFactory.java:259)
    at org.apache.openejb.config.FinderFactory.create(FinderFactory.java:77)
    at org.apache.openejb.config.FinderFactory.createFinder(FinderFactory.java:66)
    at org.apache.openejb.config.DeploymentLoader.addWebModule(DeploymentLoader.java:836)
    ... 19 more

May 04, 2020 5:47:49 PM org.apache.catalina.startup.HostConfig deployWAR
GRAVE: Erreur lors du déploiement de l'archive /Users/bcassistat/IdeaProjetcs/TomEETest/target/apache-tomee/webapps/ROOT.war de l'application web
java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[]]
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:904)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:649)
    at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:1083)
    at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1880)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)

May 04, 2020 5:47:49 PM org.apache.catalina.startup.HostConfig deployWAR
INFOS: Deployment of web application archive /Users/bcassistat/IdeaProjetcs/TomEETest/target/apache-tomee/webapps/ROOT.war has finished in 474 ms
May 04, 2020 5:47:49 PM org.apache.coyote.AbstractProtocol start
INFOS: Starting ProtocolHandler ["http-bio-8080"]
May 04, 2020 5:47:49 PM org.apache.coyote.AbstractProtocol start
INFOS: Starting ProtocolHandler ["ajp-bio-8009"]
May 04, 2020 5:47:49 PM org.apache.catalina.startup.Catalina start
INFOS: Server startup in 637 ms

根据我的研究,它看起来像是一个带有 Java 8 的 ASM4 的错误:java.lang.IllegalArgumentException at org.apache.xbean.asm4.ClassReader.<init>。但是我使用的最新TomEE版本依赖于应该支持Java 8的ASM5。为什么只有在添加Hibernate依赖时才会出现问题?而且 Hibernate 5.4 似乎与 Java 8 兼容。

【问题讨论】:

看来降级到 Hibernate 5.2.18.Final 解决了这个问题。不过,我不确定为什么更新的版本会失败...... 【参考方案1】:

问题

TomEE Webapp Archetype 在版本 1.7.1 中将启动一个(相当)旧的 TomEE 实例(运行时环境),请参阅:

INFOS:启动 Servlet 引擎:Apache Tomcat (TomEE)/7.0.55 (1.7.1)

INFOS:构建日期:20140912

解决方案

改为使用8.0.x 版本中的TomEE Webapp Archetype(最新:8.0.6)。这将修复 ASM 情况,因为容器启动时的运行时依赖项将匹配 Hibernate 5.4.x 的依赖项。

提醒一下:检查/验证每个(编译和)runtime dependency of Hibernate 5.4.x 是在容器环境的 /lib 目录中提供的,还是捆绑在应用程序的 .war 文件中的。

【讨论】:

此外,您应该检查 ***.com/questions/40818396 与带有 TomEE 8.0.x (7.0.x和 7.1.x)

以上是关于如何解决 TomEE 8.x、Hibernate 5.4 和 Java 8 的 ASM 问题?的主要内容,如果未能解决你的问题,请参考以下文章

如何使用测试资源运行嵌入式 TomEE 进行集成测试

如何在 Tomee docker 容器上启用 https?

如何在 TomEE 中定义 MySQL 数据源?

使用 Postgres DB 的 Arquillian 的 Tomee 用户缺少权限或找不到对象

Tomcat和TomEE、TomEE和TomEE Plus有啥区别

idea导入项目所有目录不是tomee主目录构建