spring 当WebSocket被启用时,为什么weblogic中的会话不过期?

lokaqttq  于 2022-12-21  发布在  Spring
关注(0)|答案(1)|浏览(182)

我开发了一个Spring Boot 2.1.0 web应用程序,并使用Weblogic 12.2.1.4作为web服务器。当我启用WebSocket时,会话在Weblogic中没有过期,但在嵌入的Tomcat中工作正常,会话过期。
我使用Weblogic时的一些配置如下:
pom.xml

<dependency>
    <groupId>org.webjars</groupId>
    <artifactId>sockjs-client</artifactId>
    <version>1.0.2</version>
</dependency>
<dependency>
    <groupId>org.webjars</groupId>
    <artifactId>stomp-websocket</artifactId>
    <version>2.3.3</version>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-amqp</artifactId>
</dependency>

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-websocket</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-tomcat</artifactId>
    <scope>provided</scope>
    <exclusions>
        <exclusion>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-websocket</artifactId>
        </exclusion>
    </exclusions>
</dependency>

weblogic.xml

<wls:context-root>/</wls:context-root>
<wls:charset-params>
    <wls:input-charset>
        <wls:resource-path>/*</wls:resource-path>
        <wls:java-charset-name>UTF-8</wls:java-charset-name>
    </wls:input-charset>
</wls:charset-params>

<wls:jsp-descriptor>
    <wls:page-check-seconds>8</wls:page-check-seconds>
</wls:jsp-descriptor>

<wls:container-descriptor>
    <wls:prefer-application-packages>
        <wls:package-name>org.slf4j.*</wls:package-name>
        <wls:package-name>com.fasterxml.jackson.*</wls:package-name>
        <wls:package-name>oracle.*</wls:package-name>
        <wls:package-name>org.springframework.*</wls:package-name>
        <wls:package-name>org.apache.cxf.*</wls:package-name>
    </wls:prefer-application-packages>
</wls:container-descriptor>

<wls:session-descriptor>
    <wls:timeout-secs>1800</wls:timeout-secs>
</wls:session-descriptor>

WebSocektConfig.java

@Configuration
@EnableScheduling
@EnableWebSocketMessageBroker
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {

    @Override
    public void configureMessageBroker(MessageBrokerRegistry config) {
        config.enableSimpleBroker("/topic","/queue");
        config.setApplicationDestinationPrefixes("/app");
    }

    @Override
    public void registerStompEndpoints(StompEndpointRegistry registry) {
        registry.addEndpoint("/websocket").withSockJS();
    }
}

Index.jsp

<script src="<c:url value='/View/header/assets/websocketJs/js/sockjs.min.js'/>"></script>
<script src="<c:url value='/View/header/assets/websocketJs/js/stomp.min.js'/>"></script>
<script>
    var stompClient = null;
    function connectWebsocket() {
        var socket = new SockJS('/websocket');
        stompClient = Stomp.over(socket);
        stompClient.connect({}, function (frame) {
            console.log('Connected: ' + frame);
            stompClient.subscribe('/user/queue/msg', function (res) {
                showMessageToUser(JSON.parse(res.body));
            });
        });
    }
</script>

对于此问题,是否有任何解决方案或Weblogic配置?
如果您有任何建议,可以帮助我,请添加评论或回答.
谢谢。

h7appiyu

h7appiyu1#

我也遇到了同样的问题。经过大量的调查,我终于解决了,在 * weblogic.xml * 中放置了以下设置:

<session-descriptor>
        <timeout-secs>3600</timeout-secs>
        <cookie-max-age-secs>3600</cookie-max-age-secs>
  </session-descriptor>

重要的部分是:<cookie-max-age-secs>,它使会话ID cookie和会话ID过期。请注意,在这种方式下,WebSocket不会使会话保持活动状态。

相关问题