Skip to content

Commit

Permalink
chore: add load-on-startup configuration for custom Vaadin servlet
Browse files Browse the repository at this point in the history
As of Flow 23.2, Vite dev-server needs VaadinServlet to be initialized before
to start. In order to have Vite starting eagerly (before any HTTP request),
VaadinServlet must be registered with load-on-startup attribute to a value
greater than zero. For custom VaadinServlet this must be done explicitly by
the developer.
This change updates example code defining custom Vaadin Servlet by adding
load-on-startup setting.

Part of vaadin/flow#14479
  • Loading branch information
mcollovati committed Sep 13, 2022
1 parent 248dd86 commit 7bafc95
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
5 changes: 3 additions & 2 deletions articles/advanced/i18n-localization.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ mvn jetty:run -Dvaadin.i18n.provider=com.vaadin.example.ui.TranslationProvider
When using the annotation, you could have the servlet class as:
[source,java]
----
@WebServlet(urlPatterns = "/*", name = "slot", asyncSupported = true, initParams = {
@WebInitParam(name = Constants.I18N_PROVIDER, value = "com.vaadin.example.ui.TranslationProvider") })
@WebServlet(urlPatterns = "/*", name = "slot", asyncSupported = true, loadOnStartup = 1,
initParams = { @WebInitParam(name = Constants.I18N_PROVIDER, value = "com.vaadin.example.ui.TranslationProvider") })
public class ApplicationServlet extends VaadinServlet {
}
----
Expand All @@ -49,6 +49,7 @@ Or, using the [filename]#web.xml# file:
<servlet-class>
com.vaadin.flow.server.VaadinServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
<init-param>
<param-name>i18n.provider</param-name>
Expand Down
5 changes: 3 additions & 2 deletions articles/configuration/npm-pnpm.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ Alternatively, you can use the Servlet 3.0 `@WebServlet` annotation:

[source,java]
----
@WebServlet(urlPatterns = "/*", name = "myservlet", asyncSupported = true, initParams = {
@WebInitParam(name = "pnpm.enable", value = "true") })
@WebServlet(urlPatterns = "/*", name = "myservlet", asyncSupported = true, loadOnStartup = 1,
initParams = { @WebInitParam(name = "pnpm.enable", value = "true") })
public class CustomServlet extends VaadinServlet {
}
----
Expand All @@ -88,6 +88,7 @@ or use the traditional [filename]#web.xml# file:
<servlet-class>
com.vaadin.flow.server.VaadinServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
<init-param>
<param-name>pnpm.enable</param-name>
Expand Down
4 changes: 3 additions & 1 deletion articles/configuration/properties.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ You can use the Servlet 3.0 `@WebServlet` annotation, which requires you to conf

[source,java]
----
@WebServlet(urlPatterns = "/*", name = "myservlet", asyncSupported = true, initParams = {
@WebServlet(urlPatterns = "/*", name = "myservlet", asyncSupported = true, , loadOnStartup = 1,
initParams = {
@WebInitParam(name = "frontend.url.es6", value = "http://mydomain.com/es6/"),
@WebInitParam(name = "frontend.url.es5", value = "http://mydomain.com/es5/") })
public class MyServlet extends VaadinServlet {
Expand All @@ -73,6 +74,7 @@ Yet another approach is to use the [filename]#web.xml# file:
<servlet-class>
com.vaadin.flow.server.VaadinServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
<init-param>
<param-name>frontend.url.es6</param-name>
Expand Down
2 changes: 1 addition & 1 deletion articles/integrations/embedding/exporter.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public final class UserService {

[source,java]
----
@WebServlet(urlPatterns = { "/vaadin/*" })
@WebServlet(urlPatterns = { "/vaadin/*" }, asyncSupported = true, loadOnStartup = 1)
public class WebComponentVaadinServlet extends VaadinServlet {
}
----
Expand Down

0 comments on commit 7bafc95

Please sign in to comment.