【问题标题】:spring websocket with spring security start failed with "No bean named 'stompWebSocketHandlerMapping' is defined'带有弹簧安全启动的弹簧 websocket 失败,“没有定义名为 'stompWebSocketHandlerMapping' 的 bean”
【发布时间】:2016-03-23 11:21:02
【问题描述】:

spring boot 1.3.0 版本发布。

错误日志是

13:00:50.888 [main] 错误 os.boot.SpringApplication - 应用程序 启动失败 org.springframework.beans.factory.NoSuchBeanDefinitionException: 否 名为“stompWebSocketHandlerMapping”的 bean 定义在 org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:698) ~[spring-beans-4.2.3.RELEASE.jar:4.2.3.RELEASE] 在 org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1175) ~[spring-beans-4.2.3.RELEASE.jar:4.2.3.RELEASE] 在 org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:284) ~[spring-beans-4.2.3.RELEASE.jar:4.2.3.RELEASE] 在 org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-4.2.3.RELEASE.jar:4.2.3.RELEASE] 在 org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1057) ~[spring-context-4.2.3.RELEASE.jar:4.2.3.RELEASE] 在 org.springframework.security.config.annotation.web.socket.AbstractSecurityWebSocketMessageBrokerConfigurer.afterSingletonsInstantiated(AbstractSecurityWebSocketMessageBrokerConfigurer.java:222) ~[spring-security-config-4.0.3.RELEASE.jar:4.0.3.RELEASE] 在 org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:792) ~[spring-beans-4.2.3.RELEASE.jar:4.2.3.RELEASE] 在 org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:838) ~[spring-context-4.2.3.RELEASE.jar:4.2.3.RELEASE] 在 org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:537) ~[spring-context-4.2.3.RELEASE.jar:4.2.3.RELEASE] 在 org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118) ~[spring-boot-1.3.0.RELEASE.jar:1.3.0.RELEASE] 在 org.springframework.boot.SpringApplication.refresh(SpringApplication.java:752) ~[spring-boot-1.3.0.RELEASE.jar:1.3.0.RELEASE] 在 org.springframework.boot.SpringApplication.doRun(SpringApplication.java:347) ~[spring-boot-1.3.0.RELEASE.jar:1.3.0.RELEASE] 在 org.springframework.boot.SpringApplication.run(SpringApplication.java:295) ~[spring-boot-1.3.0.RELEASE.jar:1.3.0.RELEASE] 在 com.d2js.platform.manager.Main.main(Main.java:28) [classes/:na]

我的 websocket 配置类

@Configuration
@EnableWebSocket
public class WebSocketConfig implements WebSocketConfigurer {

    @Autowired
    private final TeacherMonitorHandler teacherMonitorHandler = null;

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        registry.addHandler(teacherMonitorHandler, "/websocket/teacherMonitor");
    }
}

websocket 安全配置类:

@Configuration
public class WebSocketSecurityConfig extends AbstractSecurityWebSocketMessageBrokerConfigurer {
    @Override
    protected void configureInbound(MessageSecurityMetadataSourceRegistry messages) {
        messages.anyMessage().permitAll();
    }
}

【问题讨论】:

    标签: spring spring-security spring-boot spring-websocket


    【解决方案1】:

    WebSocket Security 用于 STOMP 子协议并依赖于 STOMP 代理配置。

    您必须将@EnableWebSocket 更改为@EnableWebSocketMessageBroker 并继续使用AbstractSecurityWebSocketMessageBrokerConfigurer 配置。

    顺便说一句,在这种情况下你不需要WebSocketConfigurer

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-09-08
      • 1970-01-01
      • 2019-09-12
      • 2019-01-12
      • 2017-08-23
      • 2013-08-08
      • 2020-08-26
      • 1970-01-01
      相关资源
      最近更新 更多