Spring security 4.0.1 and Spring 4.2.0.RC1 stompBrokerRelayMessageHandler bean error with RabbitMQ

2.2k views Asked by At

I have an spring boot application. I have just upgrade my pom file to use spring security 4.0.1 together with spring-boot-starter-parent 1.3.0.M1 and i am seeing this error when i changed to spring boot 1.3.0.M1.

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:825)
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.finishRefresh(EmbeddedWebApplicationContext.java:140)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:524)
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:678)
    at org.springframework.boot.SpringApplication.doRun(SpringApplication.java:339)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:274)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:931)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:920)
    at org.syncServer.core.Application.main(Application.java:56)
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:455)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:367)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    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)
    ... 14 common frames omitted
Caused by: java.lang.ClassNotFoundException: reactor.io.codec.Codec
    at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 29 common frames omitted

here is a the implementation of the the WebSocketMessageBrokerConfigurer interface

@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig  implements WebSocketMessageBrokerConfigurer {
    /// AbstractSecurityWebSocketMessageBrokerConfigurer


    @Override
    public void configureMessageBroker(MessageBrokerRegistry config) {
//      config.enableSimpleBroker("/topic/", "/queue/");
        config.enableStompBrokerRelay("/topic/",
                                      "/queue/",
                                      "/sync/", 
                                      "/syncError/", 
                                      "/syncUpgrade/", 
                                      // the queues that starts with "/exchange/amp.direct/" will be autodelete queues
                                      "/exchange/amp.direct/syncError/",
                                      "/exchange/amp.direct/syncCreateAccount/"

                                        )
        .setRelayHost("127.0.0.6")
        .setRelayPort(61613)
        .setClientLogin("guest")
        .setClientPasscode("guest")
        .setSystemLogin("guest")
        .setSystemPasscode("guest")
        .setSystemHeartbeatSendInterval(5000)
        .setSystemHeartbeatReceiveInterval(4000)
        ;


        // this is the prefix of the app. 
        // on the controller side this will be deleted automatically
        // thus when using 
        config.setApplicationDestinationPrefixes("/app");
    }

    @Override
    public void registerStompEndpoints(StompEndpointRegistry registry) {
        registry.addEndpoint("/syncServerEndPoint");

    }


    @Override
    public void configureClientInboundChannel(ChannelRegistration channelRegistration) {

    }

    @Override
    public void configureClientOutboundChannel(ChannelRegistration channelRegistration) {
    }

    @Override
    public boolean configureMessageConverters(List<MessageConverter> arg0) {

        return true;
    }

    @Override
    public void configureWebSocketTransport(WebSocketTransportRegistration arg0) {


        // TODO Auto-generated method stub

    }

    /* (non-Javadoc)
     * @see org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer#addArgumentResolvers(java.util.List)

     */
    @Override
    public void addArgumentResolvers(List<HandlerMethodArgumentResolver> arg0) {
        System.out.println("WEB SOCKET ARGUMENT RESOLVER");

    }

    /* (non-Javadoc)
     * @see org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer#addReturnValueHandlers(java.util.List)
     *
     */
    @Override
    public void addReturnValueHandlers(
            List<HandlerMethodReturnValueHandler> arg0) {
        System.out.println("WEB SOCKET RETURN VALUE HANDLER");

    }

my pom file has the entires:

<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>

<dependency>
    <groupId>org.projectreactor</groupId>
    <artifactId>reactor-spring</artifactId>
    <version>1.0.1.RELEASE</version>
</dependency>

Why i am getting this error here. I am using RabitMQ as a broker

Addition: I have seen that if I comment out the enableStompBrokerRelay in my WebSocketConfig and enable correspondignlly the simple broker i.e.

config.enableSimpleBroker("/topic/", "/queue/");

the app starts just fine.

So this is some configuration issue. netstat -apn shows that my rabbit is listenning on port 127.0.0.6 port 61613 as expected.

tcp 0 0 127.0.0.6:61613 0.0.0.0:* LISTEN 2318/beam.smp

credentials of guest guest are also good i.e. i connected to http://localhost:15672/ made sure that guest user exists and it has the admin rights.

the question is now what is this Reactor2StompCodec class supposed to do. I am not able to find sample working configuration on the github

ADDITION 18 June 2015: I was not able to understand the problem but i found a workaround i.e. spring-boot-starter-parent : 1.2.5.BUILD-SNAPSHOT and i forced the spring security version in my pom file trough an property i.e. spring-security.version : 4.0.2.CI-SNAPSHOT . With this constelation it does work. It is interesting that if i change the spring-boot-starter-parent to 1.3.0.BUILD-SNAPSHOT or 1.3.0.M1 it does not work. So maybe this has something to do with the spring boot project. At least i have a workaround now where i can use spring security 4.0

1

There are 1 answers

0
Tito On

found the answer i.e. from the link below:

"The latest version of Spring needs reactor 2.0, "

https://github.com/spring-projects/spring-boot/issues/3459

Changed the reactor groupid to the one below and it all works now :

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

    <dependency>
        <groupId>io.projectreactor</groupId>
        <artifactId>reactor-net</artifactId>
    <version>2.0.4.RELEASE</version>
    </dependency>

     <dependency>
        <groupId>io.netty</groupId>
        <artifactId>netty-all</artifactId>
        <version>4.0.30.Final</version>
    </dependency>