简体   繁体   English

Vaadin Spring Security

[英]Vaadin Spring Security

I have been working from an example I found, here's the link to the Git repo: 我一直在使用发现的示例进行工作,这是指向Git存储库的链接:

https://github.com/basakpie/vaadin8-spring-security-sample https://github.com/basakpie/vaadin8-spring-security-sample

It works great, it's just what I need, except for one thing: I need Server Push. 它工作得很好,这正是我所需要的,除了一件事:我需要服务器推送。

Here's what I've done so far: 到目前为止,这是我所做的:

  • added the Vaadin Push dependency 添加了Vaadin Push依赖
  • added the following lines to the start of the MainUI.init() method: 在MainUI.init()方法的开头添加了以下几行:

     getPushConfiguration().setTransport(Transport.WEBSOCKET); getPushConfiguration().setPushMode(PushMode.AUTOMATIC); 
  • Added the following fields to the MainUI class: 在MainUI类中添加了以下字段:

     Label time = new Label(); Timer timer; 
  • Added the following method to the MainUI class: 在MainUI类中添加了以下方法:

     private void updateTime() { access(() -> time.setValue(String.format("The server-side time is %s", LocalTime.now().format(DateTimeFormatter.ofPattern("HH:mm:ss"))))); } 
  • Finally, added the following to the end of the MainUI.init() method: 最后,将以下内容添加到MainUI.init()方法的末尾:

     timer = new Timer(); timer.schedule(new TimerTask() { @Override public void run() { updateTime(); } }, 1000L, 1000L); 

It mostly works. 它主要工作。 I am able to see the current system time updating every second. 我能够看到当前系统时间每秒钟更新一次。 But when I hit refresh in the browser, the application just hangs with the vaadin loading spinner. 但是,当我在浏览器中单击“刷新”时,该应用程序仅与vaadin加载微调器一起挂起。 There are no error messages. 没有错误消息。

I have tried the following alternatives: 我尝试了以下替代方法:

Adding the method 添加方法

public void attach() {
    getPushConfiguration().setTransport(Transport.WEBSOCKET);
    getPushConfiguration().setPushMode(PushMode.AUTOMATIC);
}

and removing the getPushConfiguration lines from init() 并从init()删除getPushConfiguration

This solves the hanging problem, but the push does not work - no errors, just the time is not displayed at all. 这解决了挂起问题,但是推送不起作用-没有错误,只是时间根本不显示。

I also tried adding a @Push annotation to MainUI . 我也尝试添加一个@Push注释MainUI This results in the same behaviour as before - freezing on refresh. 结果与以前相同-刷新时冻结。

How can I fix this? 我怎样才能解决这个问题? Any suggestions would be welcome. 欢迎大家提出意见。

Try out the below procedure: 尝试以下过程:

  1. Add @Push to the MainUI.java file @Push添加到MainUI.java文件

    @Push(transport = Transport.WEBSOCKET,value = PushMode.AUTOMATIC)

  2. Instead of : 代替 :

    getPushConfiguration().setTransport(Transport.WEBSOCKET); getPushConfiguration().setPushMode(PushMode.AUTOMATIC);

  3. Add @PreDestroy to exit the timer when you navigate from the mainUI 从mainUI导航时,添加@PreDestroy退出计时器

    @PreDestroy void destroy() { timer.cancel(); }

Find the complete revised code HERE 此处找到完整的修订代码

https://gist.github.com/cansoftinc/351452ee0e616d353519f147c4a961ba https://gist.github.com/cansoftinc/351452ee0e616d353519f147c4a961ba

I Had exactly the same problem and my solution to this was to implement the vaadin servlet . 我遇到了完全相同的问题,对此的解决方案是实现vaadin servlet Check this for more information. 检查以获取更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM