【问题标题】:Spring4 sessionSpring4会话
【发布时间】:2014-12-04 07:25:59
【问题描述】:

对不起!我在这里有个问题。哪个版本的 Spring 是“org.springframework.session.*”?我根本无法在 Spring4.0 jar 中找到它。 这是课程:

public abstract class AbstractSessionWebSocketMessageBrokerConfigurer<S extends ExpiringSession>
            extends AbstractWebSocketMessageBrokerConfigurer {
    @Autowired
    @SuppressWarnings("rawtypes")
    private SessionRepository sessionRepository;
    @Autowired
    private ApplicationEventPublisher eventPublisher;

    @Override
    public void configureClientInboundChannel(ChannelRegistration registration) {
        registration.setInterceptors(sessionRepositoryInterceptor());
    }

    @Override
    public final void registerStompEndpoints(StompEndpointRegistry registry) {
        configureStompEndpoints(new SessionStompEndpointRegistry(registry,sessionRepositoryInterceptor()));
    }

    /**
     * Register STOMP endpoints mapping each to a specific URL and (optionally)
     * enabling and configuring SockJS fallback options with a
     * {@link SessionRepositoryMessageInterceptor} automatically added as an
     * interceptor.
     *
     * @param registry
     *            the {@link StompEndpointRegistry} which automatically has a
     *            {@link SessionRepositoryMessageInterceptor} added to it.
     */
    protected abstract void configureStompEndpoints(StompEndpointRegistry registry);

    @Override
    public void configureWebSocketTransport(
            WebSocketTransportRegistration registration) {
        registration.addDecoratorFactory(wsConnectHandlerDecoratorFactory());
    }

    @Bean
    public WebSocketRegistryListener webSocketRegistryListener() {
        return new WebSocketRegistryListener();
    }

    @Bean
    public WebSocketConnectHandlerDecoratorFactory wsConnectHandlerDecoratorFactory() {
        return new WebSocketConnectHandlerDecoratorFactory(eventPublisher);
    }

    @Bean
    @SuppressWarnings("unchecked")
    public SessionRepositoryMessageInterceptor<S> sessionRepositoryInterceptor() {
        return new SessionRepositoryMessageInterceptor<S>(sessionRepository);
    }

    static class SessionStompEndpointRegistry implements StompEndpointRegistry {
        private final StompEndpointRegistry registry;
        private final HandshakeInterceptor interceptor;

        public SessionStompEndpointRegistry(StompEndpointRegistry registry,HandshakeInterceptor interceptor) {
            this.registry = registry;
            this.interceptor = interceptor;
        }

        public StompWebSocketEndpointRegistration addEndpoint(String... paths) {
            StompWebSocketEndpointRegistration endpoints = registry.addEndpoint(paths);
            endpoints.addInterceptors(interceptor);
            return endpoints;
        }
    }
}

【问题讨论】:

    标签: spring session websocket stomp


    【解决方案1】:

    Spring Session 是一个单独的项目:https://github.com/spring-projects/spring-session

    您应该使用一些依赖管理工具(Gradle 或 Maven)来控制您的应用程序的工件。

    在此处查看 WebScoket 示例:https://github.com/spring-projects/spring-session/tree/master/samples/websocket

    Spring Session 工件是:

    compile "org.springframework.session:spring-session:1.0.0.RC1"
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-09-17
    • 2023-03-29
    • 1970-01-01
    • 1970-01-01
    • 2016-01-16
    • 2016-03-12
    • 2019-01-12
    • 1970-01-01
    相关资源
    最近更新 更多