Documentation

Documentation versions (currently viewingVaadin 24.4 (pre))

Vaadin Spring Configuration

How to configure Spring properties in a Vaadin application.

You can use many properties to configure a Vaadin application. For example, com.vaadin.server.DeploymentConfiguration and com.vaadin.server.Constants classes are available for the numerous property names. In addition to these, you can also set Spring properties as system properties. Spring configuration properties use the same names, but are prefixed with vaadin.. See the complete list of configuration properties.

Special Configuration Parameters

Spring has several special configuration parameters, such as ones for scanning packages, preventing the handling of specific URLs, and more. They’re described in the sections that follow.

Configure Packages Scanning

To decrease the startup time during development, as well as the build time for the production bundle, Vaadin Flow excludes many packages from being scanned for annotations (e.g., ones belonging to the java and springframework packages). The set of packages that Flow excludes by default is defined in the VaadinServletContextInitializer class.

You can extend this list of packages to exclude from scannning by using the vaadin.blocked-packages property, which contains a comma-separated string. To do that, you would do something like the following:

vaadin.blocked-packages=org/bouncycastle,com/my/db/package

The allowed-packages is also a comma-separated string, but it contains a list of the only packages that need to be scanned for UI components and views. You should set this property to improve performance during development, especially in large applications. The com/vaadin/flow/component package is implicitly included and is always scanned.

vaadin.allowed-packages=com/foo/myapp/ui,com/foo/components
Note
Use either allowed-packages or blocked-packages — not both. If both are used and have values, though, blocked-packages is ignored.
Important
The previous vaadin.whitelisted-packages and vaadin.blacklisted-packages properties have been deprecated, and will be removed in the future.

Prevent Handling of Specific URLs

For some use cases, it’s desirable to exclude specific URLs from being handled by Vaadin, without changing the Vaadin URL mapping. For example, to integrate Swagger-UI, Vaadin shouldn’t handle requests for resources accessed by /swagger-ui.html.

The list of URL patterns that should not be handled by the Vaadin servlet, can be configured using the vaadin.exclude-urls property in the form of a comma-separated string.

vaadin.exclude-urls=/swagger-ui/**,/custom-service/**

This configuration only applies when the Vaadin servlet is mapped to the root mapping.

Launch Browser in Development Mode

You can configure a Spring Boot project to launch the default browser when starting the application in development mode by setting the following property:

vaadin.launch-browser = true

Following a server restart, the application refrains from opening a new browser tab until a thirty-minute interval has elapsed to avoid excessive tab proliferation. This delay is reset upon each server restart. In the event of a restart occurring before the interval lapses, a new tab will be opened thirty minutes post-restart.

The duration of the delay can be customized by configuring the vaadin.launch-browser-delay property to specify the desired number of minutes before initiating a new tab launch.

To trigger the tab opening immediately, you can perform a project cleanup (e.g., mvn clean or gradle clean). Or you can delete the tab.launch file in the build directory (e.g., target for Maven, build for Gradle).

The example below shows how to set the duration, with the value in minutes:

vaadin.launch-browser-delay = 30

Initial Data Cache in Development Mode

During development of a project, Vaadin caches automatically some initialization data. For instance, cached data includes details about resources to load, as well as dynamically generated white-lists of packages that need to be scanned for annotations. This caching is done to shorten the turnaround time of automatic restart on class modification.

Automatic caching won’t occur is your application is running in production mode. Plus, it requires that Spring Boot Development Tools be enabled.

Some project resources and classes always need to be scanned, though, and cannot rely on caching. Also, caching can produce unexpected errors after reloads. For these situations, you may want to disable caching. This can be done using the following property:

vaadin.devmode-caching = false

Spring Boot Properties

You can set properties for Spring Boot in your application.properties file.

An example of this would be setting Spring URL mapping in application.properties:

vaadin.url-mapping=/my_mapping/*

By default, URL mapping is /*.

Note
An additional servlet (e.g., /my_mapping/*) is required to handle the frontend resources for non-root servlets. The servlet can be defined in your application class. See Application class for an example.

Configure Spring MVC Applications

If you use Spring MVC, and hence the VaadinMVCWebAppInitializer sub-class, you need to populate your configuration properties.

Setting configuration properties, for example, in a Spring MVC application would look like this:

@Configuration
@ComponentScan
@PropertySource("classpath:application.properties")
public class MyConfiguration {

}

The application.properties file here is still used, but you can use any name and any property source.

Configure Spring Boot Development Tools

Sometimes when using Spring Boot Development Tools with automatic restart enabled, more than one restart can be triggered. It depends on how many files are changed at once, and how the IDE is changing monitored files. As a result, this may slow the overall restart time.

Spring Development tools has two properties in the application.properties file that can be adjusted to help and thereby improve the restart time: spring.devtools.restart.poll-interval; and spring.devtools.restart.quiet-period.

Poll interval is the frequency in which classpath directories are polled for changes. The default is 1 second. The quiet period ensures that there are no additional changes. It’s default is 400 milliseconds.

In a small project developed with Eclipse, for example, using the following smaller values can increase the restart time when changing one or a few classes:

spring.devtools.restart.poll-interval=100ms
spring.devtools.restart.quiet-period=50ms

As another example, in a project developed with IntelliJ IDEA, increasing values can ensure that restart happens only once after changing one or a few classes:

spring.devtools.restart.poll-interval=2000ms
spring.devtools.restart.quiet-period=1000ms

For larger applications, try to increase the values for these properties to avoid multiple restarts. A second more for the poll interval doesn’t matter much if everything else takes more than ten seconds to restart.

There isn’t one value that’s best for all development environments. The examples here are presented to show how to make adjustments — not as recommended values.

58B86F91-8716-4071-AC09-EE19C9A49277