RabbitMQ的Spring安全性4.0.1和Spring 4.2.0.RC1 stompBrokerRelayMessageHandler bean错误

时间:2015-06-16 16:46:15

标签: spring spring-security spring-boot stomp reactor

我有一个春季启动应用程序。我刚刚升级了我的pom文件,将spring security 4.0.1和spring-boot-starter-parent 1.3.0.M1一起使用,当我改为spring boot 1.3.0.M1时,我看到了这个错误。

public static int indexOf(char[] src, char[] sub) {
    int limit = src.length - sub.length;
    int i, j;
    for(i = 0; i < limit +1; ++i) {
        for(j = 0; j < sub.length; ++j) {
           if (src[i+j] != sub[j]) {
               break;
           }
        }
        if (j == sub.length)
               return i;
     }
   return -1;  
} 

这是WebSocketMessageBrokerConfigurer接口的实现

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

我的pom文件有entires:

@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");

    }

为什么我在这里收到此错误。我使用RabitMQ作为经纪人

补充:我已经看到,如果我在我的WebSocketConfig中注释掉enableStompBrokerRelay并启用了对应的简单代理,即

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

应用程序启动就好了。

所以这是一些配置问题。 netstat -apn显示我的兔子按预期在端口127.0.0.6端口61613上进行侦听。

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

来宾访客的凭据也很好,即我已连接到http://localhost:15672/,确保访客用户存在且具有管理员权限。

现在的问题是这个Reactor2StompCodec类应该做什么。我无法在github上找到样本工作配置

ADDITION 2015年6月18日:我无法理解这个问题,但我找到了一个解决方法,即spring-boot-starter-parent:1.2.5.BUILD-SNAPSHOT,我强制将弹簧安全版本放入我的pom文件中财产即 spring-security.version:4.0.2.CI-SNAPSHOT。有了这个安排,它确实有效。有趣的是,如果我将spring-boot-starter-parent更改为1.3.0.BUILD-SNAPSHOT或1.3.0.M1则不起作用。所以这可能与spring boot项目有关。至少我现在有一个解决方法,我可以使用spring security 4.0

1 个答案:

答案 0 :(得分:5)

找到了答案,即从以下链接中找到答案:

&#34;最新版本的Spring需要reactor 2.0,&#34;

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

将reactor groupid更改为下面的那个,现在一切正常:

temp[3]