Vaadin 8 demo application for Spring Boot.
This project demonstrates how to build Vaadin 8 applications with Spring Boot and Spring Security, use Spring dependency injection throughout the UI and backend layers, run browserless UI integration tests with UIUnitTest and Spring, and apply accessible design and more modern maintenance practices in a Vaadin 8 codebase.
- Spring Boot 2.7.18
- Vaadin 8.31.1
The project Wiki contains practical articles about the main implementation patterns in this codebase. It explains how Bakery uses Vaadin 8, Spring Boot, Spring Security, Spring Data JPA, browserless UI tests, accessibility improvements, and operational UI patterns in a maintainable legacy application.
mvn spring-boot:run
Wait for the application to start
Open http://localhost:8080/ to view the application.
Default credentials are admin@vaadin.com/admin for admin access and barista@vaadin.com/barista for normal user access.
The repository includes a local production-like stack with two containers:
mysqlruns MySQL 8 with a persistent Docker volume.appbuilds this project into an executable war and starts it with theproductionSpring profile.
If you use Vaadin commercial components, export VAADIN_PRO_KEY before building so the key is available during both image build and container runtime.
Change application-prodution.properties to create new database schema:
spring.jpa.hibernate.ddl-auto=create
Start the stack with:
docker compose up --build
Wait for approx 5 mins to data generator to run.
The application will be available at http://localhost:8080/ and MySQL at localhost:3306.
The compose file maps the existing production datasource variables to the MySQL container:
RDS_HOSTNAME=mysqlRDS_PORT=3306RDS_DB_NAME=bakeryRDS_USERNAME=bakeryRDS_PASSWORD=bakery
Stop the stack with:
docker compose down
Change application-prodution.properties to validate the database schema:
spring.jpa.hibernate.ddl-auto=validate
Rebuild the app
docker compose build app
Now data generator should skip and app starts quickly.
docker compose build up
You can remove the persisted MySQL data volume:
docker compose down -v
(After this you need to rerun data generator)
The project is configured to automatically make the build artifact runnable using java -jar.
By default you can thus also run the project by executing the war file:
java -jar target/###artifactId###-1.0-SNAPSHOT.war
If you want to produce a jar file instead of a war file, change the packaging type in pom.xml to <packaging>jar</packaging>.
You also need to configure Vaadin resources to be included into the jar:
<build>
...
<resources>
<resource>
<directory>src/main/webapp</directory>
<filtering>false</filtering>
</resource>
<resource>
<directory>src/main/resources</directory>
<filtering>false</filtering>
</resource>
</resources>
...
</build>The project also contains fast browserless UI tests built on top of TestBench UIUnitTest. These tests run entirely in the JVM, so they are useful for verifying Vaadin view logic, navigation, component state and Spring wiring without starting a browser.
The shared setup lives in src/test/java/com/vaadin/starter/bakery/ui/AbstractUITest.java. It boots a Spring-backed mock Vaadin environment, creates the UI through SpringUIProvider, exposes the WebApplicationContext for Spring navigation, and runs Spring Boot startup runners so the test data matches normal application startup.
Examples:
src/test/java/com/vaadin/starter/bakery/ui/SpringNavigationTest.javaverifies that navigation resolves Spring-managed views and injected dependencies.src/test/java/com/vaadin/starter/bakery/ui/views/storefront/StorefrontTest.javaverifies filtering and grid contents without a browser.src/test/java/com/vaadin/starter/bakery/ui/views/orderedit/*.javacontains browserless order editing tests.
Run all unit and browserless UI tests:
mvn verify
and make sure you have a valid license key installed.
Integration tests are implemented using TestBench. The tests take tens of minutes to run and are therefore included in a separate profile. To run the tests, execute
mvn verify -Pit
and make sure you have a valid license key installed.
Scalability tests can be run as follows
-
Configure the number of concurrent users and a suitable ramp up time in the end of the
src/test/scala/*.scalafiles, e.g.:setUp(scn.inject( rampUsers(50) over (60 seconds)) ).protocols(httpProtocol) -
If you are not running on localhost, configure the baseUrl in the beginning of the
src/test/scala/*.scalafiles, e.g.:val baseUrl = "http://my.server.com" -
Make sure the server is running at the given URL. To run the local server, use
mvn spring-boot:run -
Start a test from the command line, e.g.:
mvn -Pscalability gatling:execute -Dgatling.simulationClass=com.vaadin.starter.bakery.Barista -
Test results are stored into target folder, e.g.:
target/gatling/Barista-1487784042461/index.html
The project can be imported into the IDE of your choice as a Maven project
A paid a subscription with Vaadin 8 Extended Maintenance option included is required for creating a new software project from this starter. After its creation, results can be used, developed and distributed freely, but licenses for the used commercial components are required during development. The starter or its parts cannot be redistributed as a code example or template.
For full terms, see LICENSE