简体   繁体   中英

Can not upgrade infinispan to 9.1.0.Final: ClassCastException

I am trying to upgrade infinispan from 8.2.4.Final to 9.1.0.Final, but get some errors from embedded slf4j while building tomcat war-file.

Logs:

SLF4J: Class path contains multiple SLF4J bindings.

SLF4J: Found binding in [jar:file:/C:/tomcat/webapps/ROOT/WEB-INF/lib/infinispan-embedded-9.1.0.Final.jar!/org/slf4j/impl/StaticLoggerBinder.class]

SLF4J: Found binding in [jar:file:/C:/tomcat/webapps/ROOT/WEB-INF/lib/logback-classic-1.1.6.jar!/org/slf4j/impl/StaticLoggerBinder.class]

SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.

SLF4J: Actual binding is of type [org.jboss.slf4j.JBossLoggerFactory] 20-Jul-2017 16:07:34.170

ERROR [RMI TCP Connection(5)-127.0.0.1] com.myapp.context.LogbackLoggingConfigurator.configureLoggingExternal Loading logger configuration from C:\\my-files\\conf\\logback.xml

java.lang.ClassCastException : org.jboss.slf4j.JBossLoggerFactory cannot be cast to ch.qos.logback.classic.LoggerContext

The code, mentioned in logs:

public void configureLogging(final URL config) {
    final LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();

    try {
        lc.reset();

        final JoranConfigurator configurator = new JoranConfigurator();
        configurator.setContext(lc);
        configurator.doConfigure(config);
    } catch (final JoranException je) {
        logger.error("Unable to configure logback", je);
    }
    StatusPrinter.printInCaseOfErrorsOrWarnings(lc);
}

And wrong line is here: final LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();

Firstly, I excluded slf4j-api from "infinispan-embedded" dependency, but unsuccessfully because slf4j is hardcoded.

Secondly, I added <packagingExcludes>WEB-INF/lib/infinispan-embedded-9.1.0.Final.jar!/org/slf4j/impl/StaticLoggerBinder.class</packagingExcludes> to maven-war-plugin (maybe with '!' symbol we cannot get access to nested jars, but I don't find another variants). Attempt was failed.

So, how can I fix this exception? Maybe it is possible to use maven-shade-plugin? But it seems unacceptable for my project.

I have some problem. I solve it with a trick. I exclude logback from dependencies. I used infinispan-embedded as logger. But I think it is not right way to solve the problem. I think " http://infinispan.org/ " developers need to export codes about logger as another jar. Then we can exclude in maven. Actually It is not right way to be dependent logger jar because of another task.

I have some problem. I solve it with a trick. I exclude logback from dependencies. I used infinispan-embedded as logger. But I think it is not right way to solve the problem. I think " http://infinispan.org/ " developers need to export codes about logger as another jar. Then we can exclude in maven. Actually It is not right way to be dependent logger jar because of another task.

I wrote to infinispan team and they quick respond. As they said infinispan-embedded is "uber-jar" it is mean "all dependencies in one". You can use each dependencies of infinispan instead of it. infinispan-core and which you want to use.

You can see detail of the opened issue by clicking on this link https://developer.jboss.org/message/975209?et=watches.email.thread#975209 on jboss website.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM