GVKun编程网logo

Spring WebSockets XML配置不提供brokerMessagingTemplate(springmvc不用xml配置)

13

如果您想了解SpringWebSocketsXML配置不提供brokerMessagingTemplate的相关知识,那么本文是一篇不可错过的文章,我们将对springmvc不用xml配置进行全面详尽

如果您想了解Spring WebSockets XML配置不提供brokerMessagingTemplate的相关知识,那么本文是一篇不可错过的文章,我们将对springmvc不用xml配置进行全面详尽的解释,并且为您提供关于ActiveMQ 无法注入 jmsMessagingTemplate、An error happened during template parsing (template: "class path resource [templates/user.html]、Error creating bean with name ''webSocketServer''(springboot 整合 webstock)、Gorilla Websocket 中的 WriteMessage 和 ReadMessage 是如何工作的? 其他参考:的有价值的信息。

本文目录一览:

Spring WebSockets XML配置不提供brokerMessagingTemplate(springmvc不用xml配置)

Spring WebSockets XML配置不提供brokerMessagingTemplate(springmvc不用xml配置)

我试图将使用STOMP的WebSockets支持添加到使用XML配置的Spring
MVC应用程序中。到目前为止,一切进展顺利,而且我设法使WebSockets服务器侦听,并且stomp.js可以连接到该服务器并发送消息并接收响应。

我尚未设法开始工作的是对服务器向客户端发送任意消息的支持,这些消息不是对从客户端收到的消息的响应。这意味着到目前为止,这实际上只是REST的一个更复杂的版本,并不是太有用。

我的XML配置如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:websocket="http://www.springframework.org/schema/websocket"
   xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/websocket http://www.springframework.org/schema/websocket/spring-websocket.xsd">

  <websocket:message-broker>
    <websocket:stomp-endpoint path="/api/websocket/stomp" allowed-origins="*">
    </websocket:stomp-endpoint>

    <websocket:simple-broker prefix="/topic,/queue" />

    <websocket:message-converters>
        <bean>
            <property name="objectMapper" ref="objectMapper" />
        </bean>
    </websocket:message-converters>
   </websocket:message-broker>

  <bean>
    <constructor-arg name="clock" ref="clock" />
    <constructor-arg name="template" ref="brokerMessagingTemplate" />
  </bean>
</beans>

(DebugController是一个具有单个方法以返回服务器时间的类,可以同时作为REST和WS处理程序使用)

在启动时,我得到:

org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'brokerMessagingTemplate' is defined

令人沮丧的是IntelliJ为我自动完成了“
brokerMessagingTemplate”引用,我可以单击它以到达AbstractMessageBrokerConfiguration中的@Bean定义。

我假设我在XML中缺少一些配置来实现此目的,但是我无法在文档中找到这是什么。

有什么建议么?

ActiveMQ 无法注入 jmsMessagingTemplate

ActiveMQ 无法注入 jmsMessagingTemplate

 报错,显示无法注入使用 JmsMessagingTemplate jmsMessagingTemplate :

 

解决方案:

 

替换的依赖如 :

<dependency>
                   <groupId>org.messaginghub</groupId>
                   <artifactId>pooled-jms</artifactId>
        </dependency>

 

 ps:我出错时springboot版本为2.1.16.RELEASE

An error happened during template parsing (template: "class path resource [templates/user.html]

An error happened during template parsing (template: "class path resource [templates/user.html]

问题:

An error happened during template parsing (template: "class path resource [templates/user.html]")

 

 解决方法:

1.配置文件问题。根据问题描述,问题可能为想要去的地址路径错误。解决方法:修改路径。

 

 

 

 2.@RestController

@RestController相当于@Response + @Controller,作用是将return的字符串响应在界面上。

而@Controller作用是将return中的字符串拼接配置文件中的前后缀,形成一个html地址,最后在网页上指向这个地址界面。

 两者作用不同。

 

3.为变量加上get

实体类中可能没有getter and setter方法,加上。

或者可能是LomBok出问题了,重启或者刷新maven包可能可以解决。

 

4.xmlns冲突。可能同时设置了 “https: xmlns:https="http://www.w3.org/1999/xhtml" ”和 “xmlns:th="http://www.thymeleaf.org" ”。删去“https: xmlns:https="http://www.w3.org/1999/xhtml" ”即可。

 

5.(我的问题)进行select搜索时,数据库中没有id=“111”这个数据!所以导致页面跳转指向不明,导致错误TAT

 

高了,血压高了!!!

 

写代码须细心啊TAT

   

Error creating bean with name ''webSocketServer''(springboot 整合 webstock)

Error creating bean with name ''webSocketServer''(springboot 整合 webstock)

   今天踩了一个坑记录下,springboot 项目,整合 webstock, 总是报以下错误

org.springframework.beans.factory.BeanCreationException: Error creating bean with name ''webSocketServer'': Lookup method resolution failed; nested exception is java.lang.IllegalStateException: Failed to introspect Class 
...
Caused by: java.lang.IllegalStateException: Failed to introspect Class [com.safesys.monitoring.util.WebSocketServer] from ClassLoader [org.springframework.boot.devtools.restart.classloader.RestartClassLoader@2f6f3352]
...
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.determineCandidateConstructors(AutowiredAnnotationBeanPostProcessor.java:248)
...
Caused by: java.lang.ClassNotFoundException: javax.websocket.Session
...
Disconnected from the target VM, address: ''127.0.0.1:50767'', transport: ''socket''

刚刚开始,各种找错,发现只要添加 ServerEndpointExporter 就报错了

@Bean
public ServerEndpointExporter serverEndpointExporter() {
return new ServerEndpointExporter();
}

也找过很多帖子,让你注释启动test类的@RunWith(SpringRunner.class) 或者修改@SpringBootTest为测试环境之类的

反正各种找,准备放弃的时候,我尝试看看 tomcate 自身问题,因为要打 war,之前 pom 做过修改

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<!--声明spring boot内嵌tomcat的作用范围 在运行时不起作用-->
<scope>provided</scope>
</dependency>
看了注释,我注释了<scope>provided</scope> ,然后刷新包,发现真可以启动了,暂时先记录下,这个还是容器依赖的问题,要让springboot内置tomcate和web生效才行,没时间,就到这把,记录下


 

Gorilla Websocket 中的 WriteMessage 和 ReadMessage 是如何工作的? 其他参考:

Gorilla Websocket 中的 WriteMessage 和 ReadMessage 是如何工作的? 其他参考:

您可以在此处找到该函数的源代码:https://github.com/gorilla/websocket/blob/c3dd95aea9779669bb3daafbd84ee0530c8ce1c1/conn.go#L751-L774

看起来这是阻塞/同步方法。

根据跟踪他们在这里创建作家:https://github.com/gorilla/websocket/blob/c3dd95aea9779669bb3daafbd84ee0530c8ce1c1/conn.go#L766

w,err := c.NextWriter(messageType)

然后他们正在写data

if _,err = w.Write(data); err != nil {
    return err
}

这是阻塞的,因为他们在该函数的最后一行关闭连接,所以此时必须写入。

这是返回到 io.WriteCloser 变量中的 w 接口的行为。


如果服务端一直调用WriteMessage,但是没有人读取消息(客户端通过事件循环调用ReadMessage函数),是数据丢失了,还是一直保留到下一个读取请求到来,会发生什么?谢谢。

  • 您应该设置写入/读取超时。
  • 图书馆不会重复为您发送数据。您需要在您的应用程序中实现此逻辑。
  • 如果服务器已启动并接收到您的连接,(可能)它会读取您的消息(如果在执行数据之前没有停止)。
  • 如果您发送消息而服务器死机(没有收到您的消息),您的数据就会丢失。

其他参考:

  • w.Write 函数:https://github.com/gorilla/websocket/blob/c3dd95aea9779669bb3daafbd84ee0530c8ce1c1/conn.go#L650-L675
  • io.WriteCloser 界面说明:https://golang.org/pkg/io/#WriteCloser
  • Gorila Websocket 超时:https://pkg.go.dev/github.com/gorilla/websocket#Conn.SetReadDeadline
  • Gorila 的超时文档:https://pkg.go.dev/github.com/gorilla/websocket#Conn.SetReadDeadline
,

WriteMessage 函数是否同步向客户端发送字节数据?

WriteMessage 将数据写入底层网络连接。

操作系统网络连接维护数据缓冲区以传输到对等方。当对端确认对端接收到数据时,数据从缓冲区中移除。

写入操作系统网络连接在所有应用程序数据添加到缓冲区后返回。写可以阻塞等待缓冲区中的空间。

几乎总是在对等方接收数据之前应用程序写入调用返回的情况。成功调用 WriteMessage 确实意味着对等应用程序读取了数据。

或者ReadMessage是否主动从服务器获取数据(根据文档,我们需要创建一个事件循环来调用ReadMessage函数)。

ReadMessage 调用在底层网络连接上读取。

操作系统会缓冲从对等方接收到的一些数据。

读取正在运行的网络连接块,直到缓冲区中的数据可用。

如果服务器一直调用WriteMessage,但没有人阅读消息会发生什么。

WriteMessage 最终会阻塞等待操作系统传输缓冲区中的空间。

使用 write deadline 来防止在死掉或卡住的对等点上永远阻塞。

数据是丢失了,还是一直保留到下一个读取请求到来?

数据保存在操作系统发送和接收缓冲区中。

当传输缓冲区已满时,应用程序写入 websocket 连接块。

只有在对等应用程序读取数据之前对等应用程序终止,数据才会丢失。

关于Spring WebSockets XML配置不提供brokerMessagingTemplatespringmvc不用xml配置的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于ActiveMQ 无法注入 jmsMessagingTemplate、An error happened during template parsing (template: "class path resource [templates/user.html]、Error creating bean with name ''webSocketServer''(springboot 整合 webstock)、Gorilla Websocket 中的 WriteMessage 和 ReadMessage 是如何工作的? 其他参考:等相关知识的信息别忘了在本站进行查找喔。

本文标签: