当尝试将Wildfly 15升级到26,并在Wildfly 26.1.1上部署带有log4j2(spring-bot-starter-log4j2(的spring-boot应用程序(v2.7.0(时,得到类强制转换异常:
2022-09-01 16:08:48,655 ERROR [org.jboss.msc.service.fail] (ServerService Thread Pool -- 323) MSC000001: Failed to start service jboss.deployment.subunit."proj-ear.ear"."proj-service.war".undertow-deployment: org.jboss.msc.service.StartException in service jboss.deployment.subunit."proj-ear.ear"."proj-service.war".undertow-deployment: java.lang.RuntimeException: java.lang.ClassCastException: class org.jboss.logmanager.log4j.JBossLoggerContext cannot be cast to class org.apache.logging.log4j.core.LoggerContext (org.jboss.logmanager.log4j.JBossLoggerContext is in unnamed module of loader 'org.jboss.logmanager.log4j2@1.1.1.Final' @2afd9c25; org.apache.logging.log4j.core.LoggerContext is in unnamed module of loader 'deployment.proj-ear.ear.proj-service.war' @4b39e66)
at org.wildfly.extension.undertow@26.1.1.Final//org.wildfly.extension.undertow.deployment.UndertowDeploymentService$1.run(UndertowDeploymentService.java:90)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at org.jboss.threads@2.4.0.Final//org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
at org.jboss.threads@2.4.0.Final//org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:1990)
at org.jboss.threads@2.4.0.Final//org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1486)
at org.jboss.threads@2.4.0.Final//org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1377)
at java.base/java.lang.Thread.run(Thread.java:833)
at org.jboss.threads@2.4.0.Final//org.jboss.threads.JBossThread.run(JBossThread.java:513)
Caused by: java.lang.RuntimeException: java.lang.ClassCastException: class org.jboss.logmanager.log4j.JBossLoggerContext cannot be cast to class org.apache.logging.log4j.core.LoggerContext (org.jboss.logmanager.log4j.JBossLoggerContext is in unnamed module of loader 'org.jboss.logmanager.log4j2@1.1.1.Final' @2afd9c25; org.apache.logging.log4j.core.LoggerContext is in unnamed module of loader 'deployment.proj-ear.ear.proj-service.war' @4b39e66)
at io.undertow.servlet@2.2.17.Final//io.undertow.servlet.core.DeploymentManagerImpl.deploy(DeploymentManagerImpl.java:257)
at org.wildfly.extension.undertow@26.1.1.Final//org.wildfly.extension.undertow.deployment.UndertowDeploymentService.startContext(UndertowDeploymentService.java:105)
at org.wildfly.extension.undertow@26.1.1.Final//org.wildfly.extension.undertow.deployment.UndertowDeploymentService$1.run(UndertowDeploymentService.java:87)
... 8 more
Caused by: java.lang.ClassCastException: class org.jboss.logmanager.log4j.JBossLoggerContext cannot be cast to class org.apache.logging.log4j.core.LoggerContext (org.jboss.logmanager.log4j.JBossLoggerContext is in unnamed module of loader 'org.jboss.logmanager.log4j2@1.1.1.Final' @2afd9c25; org.apache.logging.log4j.core.LoggerContext is in unnamed module of loader 'deployment.proj-ear.ear.proj-service.war' @4b39e66)
at deployment.proj-ear.ear.proj-service.war//org.springframework.boot.logging.log4j2.Log4J2LoggingSystem.getLoggerContext(Log4J2LoggingSystem.java:401)
at deployment.proj-ear.ear.proj-service.war//org.springframework.boot.logging.log4j2.Log4J2LoggingSystem.beforeInitialize(Log4J2LoggingSystem.java:154)
at deployment.proj-ear.ear.proj-service.war//org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationStartingEvent(LoggingApplicationListener.java:232)
at deployment.proj-ear.ear.proj-service.war//org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:213)
at deployment.proj-ear.ear.proj-service.war//org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:176)
at deployment.proj-ear.ear.proj-service.war//org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:169)
at deployment.proj-ear.ear.proj-service.war//org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:143)
at deployment.proj-ear.ear.proj-service.war//org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:131)
at deployment.proj-ear.ear.proj-service.war//org.springframework.boot.context.event.EventPublishingRunListener.starting(EventPublishingRunListener.java:79)
at deployment.proj-ear.ear.proj-service.war//org.springframework.boot.SpringApplicationRunListeners.lambda$starting$0(SpringApplicationRunListeners.java:56)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
at deployment.proj-ear.ear.proj-service.war//org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:120)
at deployment.proj-ear.ear.proj-service.war//org.springframework.boot.SpringApplicationRunListeners.starting(SpringApplicationRunListeners.java:56)
at deployment.proj-ear.ear.proj-service.war//org.springframework.boot.SpringApplication.run(SpringApplication.java:299)
at deployment.proj-ear.ear.proj-service.war//org.springframework.boot.web.servlet.support.SpringBootServletInitializer.run(SpringBootServletInitializer.java:175)
at deployment.proj-ear.ear.proj-service.war//org.springframework.boot.web.servlet.support.SpringBootServletInitializer.createRootApplicationContext(SpringBootServletInitializer.java:155)
at deployment.proj-ear.ear.proj-service.war//org.springframework.boot.web.servlet.support.SpringBootServletInitializer.onStartup(SpringBootServletInitializer.java:97)
at deployment.proj-ear.ear.proj-service.war//org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:174)
at io.undertow.servlet@2.2.17.Final//io.undertow.servlet.core.DeploymentManagerImpl$1.call(DeploymentManagerImpl.java:204)
at io.undertow.servlet@2.2.17.Final//io.undertow.servlet.core.DeploymentManagerImpl$1.call(DeploymentManagerImpl.java:187)
at io.undertow.servlet@2.2.17.Final//io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:42)
at io.undertow.servlet@2.2.17.Final//io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43)
at org.wildfly.extension.undertow@26.1.1.Final//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1544)
at org.wildfly.extension.undertow@26.1.1.Final//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1544)
at org.wildfly.extension.undertow@26.1.1.Final//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1544)
at org.wildfly.extension.undertow@26.1.1.Final//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1544)
at org.wildfly.extension.undertow@26.1.1.Final//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1544)
at io.undertow.servlet@2.2.17.Final//io.undertow.servlet.core.DeploymentManagerImpl.deploy(DeploymentManagerImpl.java:255)
... 10 more
如果试图使用jboss-deployment-structure.xml排除jboss日志记录子系统,错误消失了,但开始以这种格式记录(重复的时间戳和其他信息(:
2022-09-01 14:00:45,422 INFO [org.hibernate.validator.internal.util.Version] (background-preinit) HV000001: Hibernate Validator 6.0.23.Final
2022-09-01 14:00:45,427 INFO [stdout] (ServerService Thread Pool -- 189)
2022-09-01 14:00:45,427 INFO [stdout] (ServerService Thread Pool -- 189) . ____ _ __ _ _
2022-09-01 14:00:45,427 INFO [stdout] (ServerService Thread Pool -- 189) /\ / ___'_ __ _ _(_)_ __ __ _
2022-09-01 14:00:45,427 INFO [stdout] (ServerService Thread Pool -- 189) ( ( )___ | '_ | '_| | '_ / _` |
2022-09-01 14:00:45,427 INFO [stdout] (ServerService Thread Pool -- 189) \/ ___)| |_)| | | | | || (_| | ) ) ) )
2022-09-01 14:00:45,428 INFO [stdout] (ServerService Thread Pool -- 189) ' |____| .__|_| |_|_| |___, | / / / /
2022-09-01 14:00:45,428 INFO [stdout] (ServerService Thread Pool -- 189) =========|_|==============|___/=/_/_/_/
2022-09-01 14:00:45,428 INFO [stdout] (ServerService Thread Pool -- 189) :: Spring Boot :: (v2.7.3)
2022-09-01 14:00:45,428 INFO [stdout] (ServerService Thread Pool -- 189)
2022-09-01 14:00:45,497 INFO [stdout] (ServerService Thread Pool -- 189) 2022-09-01 14:00:45.492 INFO 46824 --- [ead Pool -- 189] c.n.a.s.ServiceApp : Starting ServiceApp using Java 17.0.4.1 on NET001L148 with PID 46824 (started by Ajay Agarwal in D:jboss-Wildfly-26.1.1.Finalbin)
2022-09-01 14:00:45,501 INFO [stdout] (ServerService Thread Pool -- 189) 2022-09-01 14:00:45.501 INFO 46824 --- [ead Pool -- 189] c.n.a.s.ServiceApp : The following 1 profile is active: "stag"
2022-09-01 14:00:46,065 INFO [stdout] (ServerService Thread Pool -- 189) 2022-09-01 14:00:46.065 INFO 46824 --- [ead Pool -- 189] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2022-09-01 14:00:46,183 INFO [stdout] (ServerService Thread Pool -- 189) 2022-09-01 14:00:46.182 INFO 46824 --- [ead Pool -- 189] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 110 ms. Found 29 JPA repository interfaces.
2022-09-01 14:00:46,986 INFO [io.undertow.servlet] (ServerService Thread Pool -- 189) Initializing Spring embedded WebApplicationContext
2022-09-01 14:00:46,986 INFO [stdout] (ServerService Thread Pool -- 189) 2022-09-01 14:00:46.986 INFO 46824 --- [ead Pool -- 189] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1461 ms
2022-09-01 14:00:47,435 INFO [stdout] (ServerService Thread Pool -- 189) 2022-09-01 14:00:47.435 INFO 46824 --- [ead Pool -- 189] o.h.j.i.u.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]
2022-09-01 14:00:47,499 INFO [stdout] (ServerService Thread Pool -- 189) 2022-09-01 14:00:47.499 INFO 46824 --- [ead Pool -- 189] o.h.Version : HHH000412: Hibernate ORM core version 5.6.10.Final
2022-09-01 14:00:47,701 INFO [stdout] (ServerService Thread Pool -- 189) 2022-09-01 14:00:47.700 INFO 46824 --- [ead Pool -- 189] o.h.a.c.Version : HCANN000001: Hibernate Commons Annotations {5.1.2.Final}
2022-09-01 14:00:47,831 INFO [stdout] (ServerService Thread Pool -- 189) 2022-09-01 14:00:47.831 INFO 46824 --- [ead Pool -- 189] o.h.d.Dialect : HHH000400: Using dialect: org.hibernate.dialect.MySQL5InnoDBDialect
2022-09-01 14:00:48,108 INFO [stdout] (ServerService Thread Pool -- 189) 2022-09-01 14:00:48.108 INFO 46824 --- [ead Pool -- 189] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000490: Using JtaPlatform implementation: [org.springframework.boot.orm.jpa.hibernate.SpringJtaPlatform]
2022-09-01 14:00:52,422 INFO [stdout] (ServerService Thread Pool -- 189) 2022-09-01 14:00:52.422 INFO 46824 --- [ead Pool -- 189] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2022-09-01 14:00:53,554 ERROR [stderr] (ServerService Thread Pool -- 189) ERROR StatusLogger Log4j2 could not find a logging implementation. Please add log4j-core to the classpath. Using SimpleLogger to log to the console...
2022-09-01 14:00:55,716 INFO [stdout] (ServerService Thread Pool -- 189) 2022-09-01 14:00:55.715 INFO 46824 --- [ead Pool -- 189] o.s.s.w.DefaultSecurityFilterChain : Will secure any request with [org.springframework.security.web.session.DisableEncodeUrlFilter@320e0b81, org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter@17a0780a, org.springframework.security.web.context.SecurityContextPersistenceFilter@5e225c74, org.springframework.security.web.header.HeaderWriterFilter@cd2bd7b, org.springframework.web.filter.CorsFilter@6ec41b1d, org.springframework.security.web.authentication.logout.LogoutFilter@778aa28f, proj.service.config.JwtRequestFilter@5c98852e, org.springframework.security.web.savedrequest.RequestCacheAwareFilter@2ad997df, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter@35beb173, org.springframework.security.web.authentication.AnonymousAuthenticationFilter@58900cb8, org.springframework.security.web.session.SessionManagementFilter@1859f345, org.springframework.security.web.access.ExceptionTranslationFilter@a35b21, org.springframework.security.web.access.intercept.FilterSecurityInterceptor@64395195]
2022-09-01 14:00:55,984 INFO [stdout] (ServerService Thread Pool -- 189) 2022-09-01 14:00:55.984 WARN 46824 --- [ead Pool -- 189] JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
2022-09-01 14:00:58,190 INFO [stdout] (ServerService Thread Pool -- 189) 2022-09-01 14:00:58.190 INFO 46824 --- [ead Pool -- 189] c.n.a.s.ServiceApp
此现有应用程序在Wildfly 15上运行良好。无论这是wildfly最新版本中的日志兼容性问题还是其他问题。运行应用程序需要做什么?
冲突是由于JBoss日志记录系统使用了它自己的Log4j SPI实现,这与Spring Boot使用的Log4j核心实现不同。
您应该禁用JBoss日志记录组件(请参阅此答案(,并将log4j-core
包添加到您的配置中。