简体   繁体   中英

RabbitMq and Spring Boot 1.5.8 error java.lang.ClassNotFoundException: reactor.io.codec.Codec

Currently I use spring boot 1.5.8 and I want to use rabbitmq with my websocket.

The following code is my configuration of websocket

    @Override
    public void configureMessageBroker(MessageBrokerRegistry config) {
        config
            .enableStompBrokerRelay("/topic", "/queue", "/exchange")
            .setRelayHost("localhost")
            .setRelayPort(5672)
            .setClientLogin("guest")
            .setClientPasscode("guest")
            .setSystemHeartbeatSendInterval(5000);
    }

I add to my gradle config the following dependencies

     compile "org.springframework.boot:spring-boot-starter-websocket"
     compile("io.projectreactor:reactor-net:2.0.5.RELEASE")
     compile("io.projectreactor:reactor-core:2.0.5.RELEASE")
     compile("io.netty:netty-all:4.0.33.Final")

Spring boot generate the following stack error

Caused by: java.lang.NoClassDefFoundError: reactor/io/codec/Codec
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at org.springframework.messaging.simp.stomp.StompBrokerRelayMessageHandler.startInternal(StompBrokerRelayMessageHandler.java:388)
    at org.springframework.messaging.simp.broker.AbstractBrokerMessageHandler.start(AbstractBrokerMessageHandler.java:164)
    at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:175)
    ... 17 common frames omitted
Caused by: java.lang.ClassNotFoundException: reactor.io.codec.Codec
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 32 common frames omitted

I don't know what I'm doing wrong. Any ideas?

I follow the ideas given by http://djeison.me/2017/11/04/spring-websocket-rabbitmq/

And also have the same problem as Spring security 4.0.1 and Spring 4.2.0.RC1 stompBrokerRelayMessageHandler bean error with RabbitMQ

在GitHub上解决了类似的问题: https : //github.com/zyro23/grails-spring-websocket/issues/26

I have a very rare situation. I will explain it.

I use IntelliJ as my principal IDE for java development. When I configure the gradle plugin with the right panel, I always use the button for refresh dependencies. The strange situation here was that when I run spring boot with bootRun inside IntelliJ, it always generate the same error as the question said. I tried the last resource that was to bootRepackage the jar. Incredible, that was the solution. After the bootRepackage, IntelliJ recognize the new class reactor.io.codec.Codec.

So if you use IntelliJ as your main IDE, try to repackage and after that maybe the error was gone.

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