9

I've successfully got the example running from here using a SimpleBroker.

My config is set up like:

@Override
public void configureMessageBroker(MessageBrokerRegistry registry) {
    registry.enableSimpleBroker("/topic");
    //registry.enableStompBrokerRelay("/queue/","/topic/").setRelayHost("localhost").setRelayPort(61614);
    registry.setApplicationDestinationPrefixes("/app");
}

When I comment out the SimpleBroker and try to use the StompBroker I get the following error.

ERROR: org.springframework.web.servlet.DispatcherServlet - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'stompBrokerRelayMessageHandler' defined in class path resource   [org/springframework/web/socket/config/annotation/DelegatingWebSocketMessageBrokerConfigurat    ion.class]: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.springframework.messaging.simp.broker.AbstractBrokerMessageHandler org.springframework.messaging.simp.config.AbstractMessageBrokerConfiguration.stompBrokerRelayMessageHandler()] threw exception; nested exception is java.lang.NoClassDefFoundError: reactor/tcp/encoding/Codec
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:592)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1094)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:989)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:700)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482)
at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:643)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:606)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:657)
at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:525)
at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:466)
at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)
at javax.servlet.GenericServlet.init(GenericServlet.java:160)
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1280)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1193)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1088)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5176)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5460)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.StandardContext.reload(StandardContext.java:3954)
at org.apache.catalina.loader.WebappLoader.backgroundProcess(WebappLoader.java:426)
at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1345)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1530)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1540)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1540)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1519)
at java.lang.Thread.run(Unknown Source)
Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.springframework.messaging.simp.broker.AbstractBrokerMessageHandler org.springframework.messaging.simp.config.AbstractMessageBrokerConfiguration.stompBrokerRelayMessageHandler()] threw exception; nested exception is java.lang.NoClassDefFoundError: reactor/tcp/encoding/Codec
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:188)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:581)
... 32 more

Am I missing some resource so that it won't create the bean stompBrokerRelayMessageHandler?

Running this on Tomcat v7.0 inside of STS and using ActiveMQ for the message broker.

user1523885
  • 101
  • 1
  • 7

7 Answers7

9

You need add this at pom.xml

<!-- Reactor -->
<dependency>
  <groupId>org.projectreactor</groupId>
  <artifactId>reactor-core</artifactId>
  <version>1.0.0.RELEASE</version>
</dependency>
<dependency>
  <groupId>org.projectreactor</groupId>
  <artifactId>reactor-tcp</artifactId>
  <version>1.0.0.RELEASE</version>
</dependency>
7

To get Reactor 2.0 working with my Spring 4.2+ environment, I've added the following dependencies:

    <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.projectreactor.spring</groupId>
        <artifactId>reactor-spring-context</artifactId>
        <version>2.0.5.RELEASE</version>
    </dependency>

See https://spring.io/blog/2015/02/18/reactor-2-0-0-rc1-with-native-reactive-streams-support-now-available

Then netty was missing in my classpath, so I've added:

    <dependency>
        <groupId>io.netty</groupId>
        <artifactId>netty-all</artifactId>
        <version>4.0.31.Final</version>
    </dependency>
Alex B
  • 1,866
  • 22
  • 17
3

Your stack trace indicates very clearly it is missing a class:

java.lang.NoClassDefFoundError: reactor/tcp/encoding/Codec

See How to read and understand the java stack trace? if you're not sure how to read it.

For any class not found problem, the most common solution is to include the corresponding jar into your classpath.

The simplest way to do this is go to http://search.maven.org and query the full class name that's missing, for example:

fc:reactor.tcp.encoding.Codec

This will tell you the class belong to reactor-tcp jar. You can either download the jar and manually add it to your classpath or simply paste the maven dependency xml to your pom file.

Community
  • 1
  • 1
gerrytan
  • 40,313
  • 9
  • 84
  • 99
2

rsaez's answer is almost right, in my case at last. I had to add this:

    <!-- Reactor -->
    <dependency>
        <groupId>org.projectreactor</groupId>
        <artifactId>reactor-core</artifactId>
        <version>1.1.6.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.projectreactor</groupId>
        <artifactId>reactor-net</artifactId>
        <version>1.1.6.RELEASE</version>
    </dependency>
dacevedo
  • 21
  • 3
2

I ran into the same issue and this worked for me. I am using Spring 4.1.6

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

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

    <dependency>
        <groupId>org.projectreactor</groupId>
        <artifactId>reactor-tcp</artifactId>
        <version>1.0.1.RELEASE</version>
    </dependency>
Nikhil Das Nomula
  • 1,863
  • 5
  • 31
  • 50
0

i have made it by following Alex Bretet above, yet only one change is the version

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

instead of 2.0.5 my app works on spring 4.3.18

ali ahmed
  • 41
  • 2
0

If you are using spring boot you can just use the amqp and reactor-netty starters:

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-amqp</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-reactor-netty</artifactId>
    </dependency>
Hans
  • 681
  • 1
  • 9
  • 22