Skip to content

Commit f17d0e7

Browse files
committed
modify Websocket package
1 parent 5e2d5fa commit f17d0e7

File tree

4 files changed

+18
-23
lines changed

4 files changed

+18
-23
lines changed

springWebSocket/src/main/java/com/us/example/config/WebMvcConfig.java

-17
This file was deleted.

springWebSocket/src/main/java/com/us/example/config/WebSecurityConfig.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ protected void configure(HttpSecurity http) throws Exception {
3131
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
3232
auth
3333
.inMemoryAuthentication()
34-
.withUser("wyf").password("wyf").roles("USER")
34+
.withUser("admin").password("admin").roles("USER")
3535
.and()
36-
.withUser("wisely").password("wisely").roles("USER");
36+
.withUser("abel").password("abel").roles("USER");
3737
}
3838
//5忽略静态资源的拦截
3939
@Override

springWebSocket/src/main/java/com/us/example/controller/WebSocketController.java

+15-3
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,18 @@ public class WebSocketController {
2929
private SimpMessagingTemplate messagingTemplate;
3030

3131

32+
@RequestMapping(value = "/login")
33+
public String login(){
34+
return "login";
35+
}
36+
@RequestMapping(value = "/ws")
37+
public String ws(){
38+
return "ws";
39+
}
40+
@RequestMapping(value = "/chat")
41+
public String chat(){
42+
return "chat";
43+
}
3244
//http://localhost:8080/ws
3345
@MessageMapping("/welcome")//浏览器发送请求通过@messageMapping 映射/welcome 这个地址。
3446
@SendTo("/topic/getResponse")//服务器端有消息时,会订阅@SendTo 中的路径的浏览器发送消息。
@@ -54,15 +66,15 @@ public void handleChat(Principal principal, Message message) {
5466
* 此处是一段硬编码。如果发送人是wyf 则发送给 wisely 如果发送人是wisely 就发送给 wyf。
5567
* 通过当前用户,然后查找消息,如果查找到未读消息,则发送给当前用户。
5668
*/
57-
if (principal.getName().equals("wyf")) {
69+
if (principal.getName().equals("admin")) {
5870
//通过convertAndSendToUser 向用户发送信息,
5971
// 第一个参数是接收消息的用户,第二个参数是浏览器订阅的地址,第三个参数是消息本身
6072

61-
messagingTemplate.convertAndSendToUser("wisely",
73+
messagingTemplate.convertAndSendToUser("abel",
6274
"/queue/notifications", principal.getName() + "-send:"
6375
+ message.getName());
6476
} else {
65-
messagingTemplate.convertAndSendToUser("wyf",
77+
messagingTemplate.convertAndSendToUser("admin",
6678
"/queue/notifications", principal.getName() + "-send:"
6779
+ message.getName());
6880
}
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
server.port=8081
1+
server.port=8090

0 commit comments

Comments
 (0)