最近几天我在玩 GranideDS 教程(使用 Spring 服务器和 AIR 客户端)
https://github.com/graniteds-tutorials/graniteds-tutorial-data
“本教程展示了如何构建一个简单的数据应用程序来管理用户帐户的数据库。所有连接的客户端都会收到通知,并使用 GraniteDS 长轮询通道与数据更新同步。”
不幸的是,我找不到任何 GraniteDS javascript 客户端库或示例。
我创建了一个 HttpServlet 来使用 http (ajax) 请求来管理(例如添加实体)持久化上下文。
我的 TestServlet.java
@WebServlet("/TestServlet")
public class TestServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(this.getServletContext());
AccountService srvObject = (AccountService) wac.getBean("testService");
//testService mean spring service annotation parameter
Account emp = new Account();
emp.setName(request.getParameter("name"));
emp.setEmail(request.getParameter("email"));
srvObject.save(emp);
response.getWriter().println("OK");
}
}
此方法正确添加实体,但连接的客户端数据未同步。我如何通知所有客户新的变化?
更新: 我试图将 DataEnabled 的发布更改为 PublishMode.ON_COMMIT
@DataEnabled(topic="dataTopic", publish=DataEnabled.PublishMode.ON_COMMIT, useInterceptor=true)
添加到 application-context.xml
<graniteds:tide-data-publishing-advice/>
在这种情况下,空中应用程序和 servlet 都会导致服务器错误:
SEVERE: 无法为 ON_COMMIT 发布模式注册同步,检查 Spring PlatformTransactionManager 是否支持并且 TransactionInterceptor 的 order 低于 TideDataPublishingInterceptor 的 order
并<graniteds:tide-data-publishing-advice order="-1"/>
没有帮助。