Thorben Auer
Thorben Auer

Reputation: 51

ClassCastingException when redeploy war in wildfly

I always get an error on redeploy a new version of my web app.

I have to undeploy and restart the server to get it working.

If i don't restart the server i get this message on deployment process:

org.apache.logging.log4j.core.LoggerContext cannot be cast to org.apache.logging.log4j.core.LoggerContext

Im running a Springboot Application as backend and Angular for frontend.

Here my maven dependencies:

 <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <version>2.4.4</version>
        <exclusions>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-logging</artifactId>
            </exclusion>
            <exclusion>
                <groupId>log4j</groupId>
                <artifactId>*</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.slf4j</groupId>
                <artifactId>*</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.apache.logging.log4j</groupId>
                <artifactId>*</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.apache.tomcat.embed</groupId>
                <artifactId>tomcat-embed-websocket</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-log4j2</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot</artifactId>
        <version>2.4.4</version>
    </dependency>

Upvotes: 2

Views: 1204

Answers (2)

FastFoot
FastFoot

Reputation: 31

This happens because there are already (implicit) log4j API dependencies on WildFly. You can configure WildFly to not add it's own API logging dependency.

A) From WildFly console: Configuration -> Subsystems -> Logging configuration

change "Add Logging Api Dependencies" to false

B) By editing the standalone.xml:

<subsystem xmlns="urn:jboss:domain:logging:8.0">
   <add-logging-api-dependencies value="false"/>

C) Alternatively, if you have a jboss-deployment-structure.xml

<deployment>
    <exclude-subsystems>
      <subsystem name="logging"/>
    </exclude-subsystems>
  </deployment>

P.S This fixed it for me with same technology stack as you

jboss doc about logging-api-dependencies

Upvotes: 3

ehsavoie
ehsavoie

Reputation: 3527

I think you should exclude org.apache.logging.log4j:

<exclusion>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>*</artifactId>
</exclusion>

as log4j:log4j was the old name

Upvotes: 0

Related Questions