当我尝试使用sockjs打开套接字时,我收到以下异常:
获取http://localhost:8080/myApp/analyst/info?t=1479231324779 404(未找到)
我已经按照这些教程1,2进行了操作。 在github中,我看到其他人面临同样的problem(for the second tutorial...).
我已经尝试过我在谷歌找到的所有内容:
更新依赖关系,更改配置,添加setAllowedOrigins()
,验证DispatcherServlet
是否存在,删除网址中的应用前缀。
此应用不使用spring-security at all,我有一个拦截器进行会话验证。当我尝试打开会话时,不会调用拦截器。
我的网络配置是:
@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer{
@Override
public void configureMessageBroker(MessageBrokerRegistry config) {
config.enableSimpleBroker("/topic/");
config.setApplicationDestinationPrefixes("/app");
}
@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
registry.addEndpoint("/analyst")
.withSockJS()
.setWebSocketEnabled(true);
}
}
WebMvc:
@Configuration
@EnableWebMvc
@ComponentScan(basePackages = {"myApp.controllers"})
public class DispatcherConfig extends WebMvcConfigurerAdapter {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**");
}
@Bean
public myInterceptor pagePopulationInterceptor() {
return new myInterceptor();
}
@Bean
public CurrencyConverter createCurrencyConverter() {
return CurrencyConverter.getInstance();
}
@Bean
public Executor taskExecutor() {
return new SimpleAsyncTaskExecutor();
}
@Override
public void addInterceptors(InterceptorRegistry registry) {
String shouldIntercept = System.getenv("DISABLE_INTERCEPTOR");
if (shouldIntercept == null || shouldIntercept.isEmpty() || !shouldIntercept.equals("true"))
{
registry.addInterceptor(pagePopulationInterceptor());
}
}
}
WebApplicationInitializer:
public void onStartup(ServletContext servletContext) throws ServletException {
WebApplicationContext context = getContext();
servletContext.addListener(new ContextLoaderListener(context));
ServletRegistration.Dynamic dispatcher = servletContext.addServlet("DispatcherServlet", new DispatcherServlet(context));
sockjs:
vm.socket = new SockJS("/myApp/Analyst");
vm.stompClient = Stomp.over(vm.socket);
vm.stompClient.connect({}, function (event) {
console.log("Hi, I am the client");
});
任何我做错的线索都会很棒! 在此先感谢:)