diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/config/CustomScopeConfigurer.java b/spring-beans/src/main/java/org/springframework/beans/factory/config/CustomScopeConfigurer.java index 446de9a344..dc1516ab02 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/config/CustomScopeConfigurer.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/config/CustomScopeConfigurer.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,6 +16,7 @@ package org.springframework.beans.factory.config; +import java.util.LinkedHashMap; import java.util.Map; import org.springframework.beans.BeanUtils; @@ -61,6 +62,20 @@ public class CustomScopeConfigurer implements BeanFactoryPostProcessor, BeanClas this.scopes = scopes; } + /** + * Add the given scope to this configurer's map of scopes. + * @param scopeName the name of the scope + * @param scope the scope implementation + * @since 4.1.1 + */ + public void addScope(String scopeName, Scope scope) { + if (this.scopes == null) { + this.scopes = new LinkedHashMap(1); + } + this.scopes.put(scopeName, scope); + } + + public void setOrder(int order) { this.order = order; } diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/WebSocketConfigurationSupport.java b/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/WebSocketConfigurationSupport.java index 6fb4c75541..a48b2538d8 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/WebSocketConfigurationSupport.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/WebSocketConfigurationSupport.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -51,7 +51,6 @@ public class WebSocketConfigurationSupport { * } * * // ... - * * } * */ diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/WebSocketMessageBrokerConfigurationSupport.java b/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/WebSocketMessageBrokerConfigurationSupport.java index 98f2812e0b..00cce677fa 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/WebSocketMessageBrokerConfigurationSupport.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/WebSocketMessageBrokerConfigurationSupport.java @@ -16,11 +16,10 @@ package org.springframework.web.socket.config.annotation; -import java.util.Collections; - import org.springframework.beans.factory.config.CustomScopeConfigurer; import org.springframework.context.annotation.Bean; import org.springframework.messaging.simp.SimpSessionScope; +import org.springframework.messaging.simp.broker.AbstractBrokerMessageHandler; import org.springframework.messaging.simp.config.AbstractMessageBrokerConfiguration; import org.springframework.messaging.simp.stomp.StompBrokerRelayMessageHandler; import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; @@ -32,8 +31,8 @@ import org.springframework.web.socket.messaging.SubProtocolWebSocketHandler; /** * Extends {@link AbstractMessageBrokerConfiguration} and adds configuration for * receiving and responding to STOMP messages from WebSocket clients. - *

- * Typically used in conjunction with + * + *

Typically used in conjunction with * {@link EnableWebSocketMessageBroker @EnableWebSocketMessageBroker} but can * also be extended directly. * @@ -46,16 +45,10 @@ public abstract class WebSocketMessageBrokerConfigurationSupport extends Abstrac private WebSocketTransportRegistration transportRegistration; - protected WebSocketMessageBrokerConfigurationSupport() { - } - - @Bean public HandlerMapping stompWebSocketHandlerMapping() { - WebMvcStompEndpointRegistry registry = new WebMvcStompEndpointRegistry(subProtocolWebSocketHandler(), getTransportRegistration(), userSessionRegistry(), messageBrokerSockJsTaskScheduler()); - registry.setApplicationContext(getApplicationContext()); registerStompEndpoints(registry); return registry.getHandlerMapping(); @@ -92,7 +85,6 @@ public abstract class WebSocketMessageBrokerConfigurationSupport extends Abstrac * } * * // ... - * * } * */ @@ -108,15 +100,15 @@ public abstract class WebSocketMessageBrokerConfigurationSupport extends Abstrac @Bean public static CustomScopeConfigurer webSocketScopeConfigurer() { CustomScopeConfigurer configurer = new CustomScopeConfigurer(); - configurer.setScopes(Collections.singletonMap("websocket", new SimpSessionScope())); + configurer.addScope("websocket", new SimpSessionScope()); return configurer; } @Bean public WebSocketMessageBrokerStats webSocketMessageBrokerStats() { - StompBrokerRelayMessageHandler brokerRelay = - stompBrokerRelayMessageHandler() instanceof StompBrokerRelayMessageHandler ? - (StompBrokerRelayMessageHandler) stompBrokerRelayMessageHandler() : null; + AbstractBrokerMessageHandler relayBean = stompBrokerRelayMessageHandler(); + StompBrokerRelayMessageHandler brokerRelay = (relayBean instanceof StompBrokerRelayMessageHandler ? + (StompBrokerRelayMessageHandler) relayBean : null); // Ensure STOMP endpoints are registered stompWebSocketHandlerMapping();