Spring Boot 未调用订阅Map

nue99wik  于 4个月前  发布在  Spring
关注(0)|答案(2)|浏览(42)

我必须使用从Web Socket返回值。我尝试使用@SubscribeMapping Annotated方法来处理并使用此块来处理我的业务。示例代码是:

@MessageMapping({"/hello"})
    @SendTo("/topic/greetings")
    public Greeting greeting(HelloMessage message) throws Exception { 
        return new Greeting("Thread Id:"+Thread.currentThread().getId()+" Hello, " + HtmlUtils.htmlEscape(message.getName()) + "!");
    }

@SubscribeMapping("/topic/greetings")
public void test(Greeting greeting){
    System.out.println("SUBSCRIBE CALLED");
}

字符串

bzzcjhmw

bzzcjhmw1#

主题前缀是自动添加.省略“/主题”

@SubscribeMapping("/greetings")
public void test(Greeting greeting){
    System.out.println("SUBSCRIBE CALLED");
}

字符串

z5btuh9x

z5btuh9x2#

你好,你可以把@SubscribeMapping改成@MessageMapping,希望对你有帮助!

相关问题