瓦丁入口点
我想知道是否/在哪里可以放置一些代码来在 Vaadin 服务器第一次初始化时运行? (不是用户第一次访问该网站)
(例如从文件加载代理设置、启动 rss 爬虫等)
很可能我在这里错过了 JavaEE 内容的技巧,我对这些内容还很陌生。
I am wondering if/where I can put some code to run the VERY first time the Vaadin server is initialized? (Not the first time a user hits the site)
(For example for loading proxy settings from files, starting rss crawlers etc.)
It's quite possible I'm missing a trick with the JavaEE stuff here, I'm pretty new to this stuff.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 ServletContextListener。这是一个接口,每次服务器启动时都会调用 contextInitialized 方法。它们使用起来非常简单,只需实现接口并将上下文侦听器添加到 web-xml 中,请参阅 此示例。
Use ServletContextListeners. It's an interface whose contextInitialized method is called everytime the server is started. They are really simple to use, just implement the interface and add your context listener to the web-xml, see this example.
另一种方法是扩展 ApplicationServlet 并覆盖init() 方法。
然后,您必须修改 .xml 文件以指向此 servlet,而不是 Vaadin 的默认值。
一旦容器启动 servlet,就会调用此方法。
Another way would be to extend ApplicationServlet and override the init() method.
Then you have to modify your .xml file to point to this servlet instead of Vaadin's default one.
This method is called once the servlet is brought up by the container.