Spring-boot: ClassNotFoundException: reactor.io.codec.Codec In 1.3.0.BUILD-SNAPSHOT

Created on 10 Jul 2015  路  14Comments  路  Source: spring-projects/spring-boot

I am getting a classnotfoundexception reactor.io.codec.Codec when using 1.3.0.BUILD-SNAPSHOT on a project that is using spring-boot-starter-websocket backed by an AMQP broker. This same project works fine when using 1.2.5.RELEASE. To reproduce the issue I created a basic spring-boot app that demonstrates the problem. You can find it here: https://dl.dropboxusercontent.com/u/58852600/amqp-bug.zip

If you build that project with mvn package and then run java -jar -Dspring.cloud.amqp='amqp://guest:guest@localhost:5672/' target/demo-0.0.1-SNAPSHOT.jar you will see

org.springframework.context.ApplicationContextException: Failed to start bean 'stompBrokerRelayMessageHandler'; nested exception is java.lang.NoClassDefFoundError: reactor/io/codec/Codec
    at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:176)
    at org.springframework.context.support.DefaultLifecycleProcessor.access$200(DefaultLifecycleProcessor.java:51)
    at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:346)
    at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:149)
    at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:112)
    at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:832)
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.finishRefresh(EmbeddedWebApplicationContext.java:140)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:525)
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:667)
    at org.springframework.boot.SpringApplication.doRun(SpringApplication.java:342)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:273)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:971)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:960)
    at demo.AmqpBugApplication.main(AmqpBugApplication.java:10)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:53)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NoClassDefFoundError: reactor/io/codec/Codec
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
    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 org.springframework.boot.loader.LaunchedURLClassLoader.doLoadClass(LaunchedURLClassLoader.java:164)
    at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:137)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at org.springframework.messaging.simp.stomp.StompBrokerRelayMessageHandler.startInternal(StompBrokerRelayMessageHandler.java:382)
    at org.springframework.messaging.simp.broker.AbstractBrokerMessageHandler.start(AbstractBrokerMessageHandler.java:164)
    at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:173)
    ... 20 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 org.springframework.boot.loader.LaunchedURLClassLoader.doLoadClass(LaunchedURLClassLoader.java:171)
    at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:137)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 35 common frames omitted

java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:53)
    at java.lang.Thread.run(Thread.java:745)
Caused by: org.springframework.context.ApplicationContextException: Failed to start bean 'stompBrokerRelayMessageHandler'; nested exception is java.lang.NoClassDefFoundError: reactor/io/codec/Codec
    at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:176)
    at org.springframework.context.support.DefaultLifecycleProcessor.access$200(DefaultLifecycleProcessor.java:51)
    at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:346)
    at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:149)
    at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:112)
    at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:832)
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.finishRefresh(EmbeddedWebApplicationContext.java:140)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:525)
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:667)
    at org.springframework.boot.SpringApplication.doRun(SpringApplication.java:342)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:273)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:971)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:960)
    at demo.AmqpBugApplication.main(AmqpBugApplication.java:10)
    ... 6 more
Caused by: java.lang.NoClassDefFoundError: reactor/io/codec/Codec
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
    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 org.springframework.boot.loader.LaunchedURLClassLoader.doLoadClass(LaunchedURLClassLoader.java:164)
    at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:137)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at org.springframework.messaging.simp.stomp.StompBrokerRelayMessageHandler.startInternal(StompBrokerRelayMessageHandler.java:382)
    at org.springframework.messaging.simp.broker.AbstractBrokerMessageHandler.start(AbstractBrokerMessageHandler.java:164)
    at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:173)
    ... 20 more
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 org.springframework.boot.loader.LaunchedURLClassLoader.doLoadClass(LaunchedURLClassLoader.java:171)
    at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:137)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 35 more
invalid

Most helpful comment

Might it make sense to provide some sort of a starter for that then? A 'STOMP' starter? I'm not really a 'serious' user. Just playing around with this stuff at the moment. But figuring out what's needed to enable the relay broker was a bit difficult to be honest. Only place I found the info was... right in this bug report. And I had to make a guess about the netty-all version because, although it seems needed (stuff doesn't work without it) the version is not managed.

This is the stuff I added to my pom in the end (slightly different / combo from stuff other people have posted here).

    <dependency>
        <groupId>io.projectreactor</groupId>
        <artifactId>reactor-core</artifactId>
    </dependency>
    <dependency>
        <groupId>io.projectreactor</groupId>
        <artifactId>reactor-net</artifactId>
    </dependency>
    <dependency>
        <groupId>io.netty</groupId>
        <artifactId>netty-all</artifactId>
        <version>4.1.2.Final</version>
    </dependency>

All 14 comments

The latest version of Spring needs reactor 2.0, looking at your POM there is an explicit 1.1.6 dependency.

<dependency>
    <groupId>org.projectreactor</groupId>
    <artifactId>reactor-net</artifactId>
    <version>1.1.6.RELEASE</version>
</dependency>

Try removing the version tag to use the managed version.

@philwebb are you sure that dependency is managed? I removed the version tag and maven is complaining the version is missing.

Oh right. I forget. They also rename the <groupId>. Try:

<dependency>
    <groupId>io.projectreactor</groupId>
    <artifactId>reactor-core</artifactId>
</dependency>

@philwebb thanks.

I also had to add

<dependency>
      <groupId>io.projectreactor</groupId>
      <artifactId>reactor-net</artifactId>
</dependency>
 <dependency>
    <groupId>io.netty</groupId>
    <artifactId>netty</artifactId>
    <version>4.0.27.Final</version>
</dependency>

curious about the netty dependency, is that something not managed? Saw the same problem happened here https://build.spring.io/browse/SPR-PERF-477/commit

Hi,

I just had this problem today. The dependencies that I added are:

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-websocket</artifactId>
        <version>4.2.4.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>io.projectreactor</groupId>
        <artifactId>reactor-core</artifactId>
        <version>2.0.7.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>io.projectreactor</groupId>
        <artifactId>reactor-net</artifactId>
        <version>2.0.7.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>io.netty</groupId>
        <artifactId>netty-all</artifactId>
        <version>4.0.33.Final</version>
    </dependency>

The following worked for me.
If I tried 2.0.7 as above I still got the error.

    <dependency>
        <groupId>io.projectreactor</groupId>
        <artifactId>reactor-core</artifactId>
        <version>2.0.5.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>io.projectreactor</groupId>
        <artifactId>reactor-net</artifactId>
        <version>2.0.5.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>io.netty</groupId>
        <artifactId>netty-all</artifactId>
        <version>4.0.33.Final</version>
    </dependency>

Why isn't the websocket starter adding all that stuff if its needed? I would have hoped the websocket starter provided a little better 'out of the box experience'.

Because it isn't always needed. It's only necessary if you're using WebSocket, STOMP and the AMQP broker relay

Might it make sense to provide some sort of a starter for that then? A 'STOMP' starter? I'm not really a 'serious' user. Just playing around with this stuff at the moment. But figuring out what's needed to enable the relay broker was a bit difficult to be honest. Only place I found the info was... right in this bug report. And I had to make a guess about the netty-all version because, although it seems needed (stuff doesn't work without it) the version is not managed.

This is the stuff I added to my pom in the end (slightly different / combo from stuff other people have posted here).

    <dependency>
        <groupId>io.projectreactor</groupId>
        <artifactId>reactor-core</artifactId>
    </dependency>
    <dependency>
        <groupId>io.projectreactor</groupId>
        <artifactId>reactor-net</artifactId>
    </dependency>
    <dependency>
        <groupId>io.netty</groupId>
        <artifactId>netty-all</artifactId>
        <version>4.1.2.Final</version>
    </dependency>

The need for the reactor-net dependency is mentioned in the Spring Framework documentation but it doesn't mention the need to also add Netty. Look like there's some room for improvement in the Spring Framework documentation there if Netty is indeed required /cc @rstoyanchev.

STOMP's a tricky one as it can be used both with and without the AMQP broker relay, however the framework documentation describes the non-broker approach as "great for getting started". Perhaps it's reasonable for us to push people towards using a broker with an appropriately configured starter. I've opened https://github.com/spring-projects/spring-boot/issues/6359.

Spring Framework docs updated https://github.com/spring-projects/spring-framework/commit/d84b9890253cf325347740e1e86cf17c43e58fe2. Also a minor comment that the broker only needs to support STOMP, i.e. it may or may not be an AMQP broker otherwise.

This error is also seen when attempting to use reactor 3 in a project that uses the spring stomp broker relay. Opting to use the spring stomp relay broker appears to prevent the adoption of reactor 3 in a project. I raised https://jira.spring.io/browse/SPR-15129 to formally note this.

hello, in my project, I need zookeeper,but last version is 3.4.13, its dependency is io.netty:netty:3.10.6.Final, but reactor need io.netty:netty:4.X锛寃hat should i do ?

hello, in my project, I need zookeeper,but last version is 3.4.13, its dependency is io.netty:netty:3.10.6.Final, but reactor need io.netty:netty:4.X锛寃hat should i do ?

It have already solved锛歶seio.netty:netty-all:4.1.31.Final.
Thx.

Was this page helpful?
0 / 5 - 0 ratings