2

来自 spring-websocket-portfolio-master WebConfig.java:

@Bean
public SimpleUrlHandlerMapping handlerMapping() {

    DefaultSockJsService sockJsService = new DefaultSockJsService(sockJsTaskScheduler());
    //sockJsService.setDummySessionCookieEnabled(true);
    HttpRequestHandler requestHandler = new SockJsHttpRequestHandler(sockJsService, stompWebSocketHandler());

    SimpleUrlHandlerMapping hm = new SimpleUrlHandlerMapping();
    hm.setOrder(-1);
    hm.setUrlMap(Collections.singletonMap("/portfolio/**", requestHandler));
    return hm;
}

我想在当前应用程序中添加 XML 配置。我在 web.xml 中有以下内容:

<servlet>
    <servlet-name>mximonitor</servlet-name>
    <servlet-class>
        org.springframework.web.servlet.DispatcherServlet
    </servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>mximonitor</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>

到目前为止我有这个(我希望它是正确的):

<!-- Following two beans were wrapped in a SimpleUrlHandlerMapping bean -->    
<bean id="sockJsService" class="org.springframework.web.socket.sockjs.support.DefaultSockJsService">
  <constructor-arg index="0" ref="sockJSTaskScheduler"/>    
</bean>

<bean id="sockJsHttpRequestHandler" class="org.springframework.web.socket.sockjs.support.SockJsHttpRequestHandler">
  <constructor-arg index="0" ref="sockJsService"/>
  <constructor-arg index="1" ref="stompWebSocketHandler"/>    
</bean>

我希望能够将新的请求处理程序添加到现有配置中。我想我会使用“SimpleUrlHandlerMapping”,但我对 Spring(以及一般的 Web 编程)相当陌生。我将如何配置?'SimpleUrlHandlerMapping' 是附加的(意味着它不会干扰现有的控制器?

在此先感谢(以及您的耐心等待),

詹姆士

4

0 回答 0