Ajay Rajvanshi
Ajay Rajvanshi

Reputation: 21

Log4j2 giving class cast exception on wildfly 26

While trying to upgrade the Wildfly 15 to 26 and deploying my spring boot application(v2.7.0) with log4j2 (spring-boot-starter-log4j2) on wildfly 26.1.1, getting class cast exception:

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 '[email protected]' @2afd9c25; org.apache.logging.log4j.core.LoggerContext is in unnamed module of loader 'deployment.proj-ear.ear.proj-service.war' @4b39e66)
    at [email protected]//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 [email protected]//org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
    at [email protected]//org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:1990)
    at [email protected]//org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1486)
    at [email protected]//org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1377)
    at java.base/java.lang.Thread.run(Thread.java:833)
    at [email protected]//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 '[email protected]' @2afd9c25; org.apache.logging.log4j.core.LoggerContext is in unnamed module of loader 'deployment.proj-ear.ear.proj-service.war' @4b39e66)
    at [email protected]//io.undertow.servlet.core.DeploymentManagerImpl.deploy(DeploymentManagerImpl.java:257)
    at [email protected]//org.wildfly.extension.undertow.deployment.UndertowDeploymentService.startContext(UndertowDeploymentService.java:105)
    at [email protected]//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 '[email protected]' @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 [email protected]//io.undertow.servlet.core.DeploymentManagerImpl$1.call(DeploymentManagerImpl.java:204)
    at [email protected]//io.undertow.servlet.core.DeploymentManagerImpl$1.call(DeploymentManagerImpl.java:187)
    at [email protected]//io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:42)
    at [email protected]//io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43)
    at [email protected]//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1544)
    at [email protected]//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1544)
    at [email protected]//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1544)
    at [email protected]//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1544)
    at [email protected]//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1544)
    at [email protected]//io.undertow.servlet.core.DeploymentManagerImpl.deploy(DeploymentManagerImpl.java:255)
    ... 10 more

If trying to use jboss-deployment-structure.xml for excluding jboss logging subsystem, the error gone but start to get logging in this format (repetitive timestamp and other info):

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.Final\bin)
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 

This existing application is running well on Wildfly 15. Whether this is the issue of logging compatibility in wildfly latest versions or something else. What need to do for running the application?

Upvotes: 2

Views: 6644

Answers (1)

jessica-rod
jessica-rod

Reputation: 261

The conflict is due to the JBoss logging system using it's own implementation of the Log4j SPI, which differs from the log4j-core implementation used by Spring Boot.

You should disable the JBoss logging components (see this answer), and add the log4j-core package to your configuration.

Upvotes: 1

Related Questions