Try it, it works for me
@Component @ServerEndpoint(value = "/instantMessageServer",configurator = SpringConfigurator.class) public class InstantMessageServer{ private static IChatService chatService; @Autowired public InstantMessageServer(IChatService chatService){ this.chatService = chatService; } public InstantMessageServer(){} } , configurator = SpringConfigurator.class) @Component @ServerEndpoint(value = "/instantMessageServer",configurator = SpringConfigurator.class) public class InstantMessageServer{ private static IChatService chatService; @Autowired public InstantMessageServer(IChatService chatService){ this.chatService = chatService; } public InstantMessageServer(){} }
I found this solution https://spring.io/blog/2013/05/23/spring-framework-4-0-m1-websocket-support but there is another failure, class annotated using @ServerEndpoint, can not get httpsession with SpringConfigurator, there is no overriding changehandler method. Perhaps, we create a separate configurator, extending SpringConfigurator and override this method that will work. I think it is better to create a Web application in real time with the help of spring -websocket api and posts.
public class ModifiedServerEndpointConfigurator extends SpringConfigurator{ @Override public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) { HttpSession httpSession = (HttpSession) request.getHttpSession(); sec.getUserProperties().put(HttpSession.class.getName(),httpSession); super.modifyHandshake(sec, request, response); } } request, HandshakeResponse response) { public class ModifiedServerEndpointConfigurator extends SpringConfigurator{ @Override public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) { HttpSession httpSession = (HttpSession) request.getHttpSession(); sec.getUserProperties().put(HttpSession.class.getName(),httpSession); super.modifyHandshake(sec, request, response); } } ); public class ModifiedServerEndpointConfigurator extends SpringConfigurator{ @Override public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) { HttpSession httpSession = (HttpSession) request.getHttpSession(); sec.getUserProperties().put(HttpSession.class.getName(),httpSession); super.modifyHandshake(sec, request, response); } } ), httpSession); public class ModifiedServerEndpointConfigurator extends SpringConfigurator{ @Override public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) { HttpSession httpSession = (HttpSession) request.getHttpSession(); sec.getUserProperties().put(HttpSession.class.getName(),httpSession); super.modifyHandshake(sec, request, response); } } ; public class ModifiedServerEndpointConfigurator extends SpringConfigurator{ @Override public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) { HttpSession httpSession = (HttpSession) request.getHttpSession(); sec.getUserProperties().put(HttpSession.class.getName(),httpSession); super.modifyHandshake(sec, request, response); } }