如何从Vaadin 14应用程序中访问`ServletContext`?

问题描述:

我问的是与问题相同的问题, 如何从Vaadin 7应用程序中访问ServletContext? ,但针对Vaadin 14.

I am asking the same as the Question, How to access ServletContext from within a Vaadin 7 app?, but for Vaadin 14.

在Vaadin 7中,Vaadin提供了简单方便的呼叫:

In Vaadin 7, Vaadin provided the simple and handy call:

ServletContext servletContext = VaadinServlet.getCurrent().getServletContext();

该特定调用不再存在于 VaadinServlet 在Vaadin 14中.

That particular call is no longer there on VaadinServlet in Vaadin 14.

➥Vaadin API中的其他地方是否有等效项?

➥ Is there an equivalent somewhere else in the Vaadin API?

我的最终目标是使用键值属性"集合来保留对我的应用范围内对象的引用.

My end goal is to use the key-value "attribute" collection to keep references to my app-wide objects.

方法仍然存在,但未记录

两种方法:

Methods still there, but not documented

Both methods:

...在Vaadin 14中仍然存在.

…are there still in Vaadin 14.

似乎第二个方法VaadinServlet::getServletContext()未在Javadocs中列出,因为它是从

It seems the second method, VaadinServlet::getServletContext(), isn't listed in the Javadocs because it's inherited from javax.servlet.GenericServlet and the Javadoc generation is run in a way that doesn't have access to that class.