> Markdown version of [Working with Spring Boot](https://vaadin.com/docs/v14/flow/integrations/spring/tutorial-spring-basic). Section index: [llms.txt](https://vaadin.com/docs/v14/flow/llms.txt)

# Using Vaadin With Spring Boot

The [Vaadin Spring](https://vaadin.com/directory/component/vaadin-spring/) add-on allows you to use Vaadin with [Spring Boot](https://spring.io/projects/spring-boot).

[Spring Boot](https://spring.io/projects/spring-boot) speeds up the development process and provides a fast and efficient development environment by emphasizing usability. It is the easiest way to use the Spring framework.

[Vaadin Start](https://start.vaadin.com/?preset=lts) is the easiest way to create an application with Spring Boot and Vaadin. You can also configure and download a Vaadin project using [Spring Initializr](https://start.spring.io/#!type=maven-project\&language=java\&packaging=jar\&jvmVersion=11\&groupId=org.vaadin\&artifactId=example-app\&name=example-app\&description=Vaadin%20project%20for%20Spring%20Boot\&packageName=org.vaadin.example-app\&dependencies=vaadin) or add the required dependencies manually to your project.

If you prefer not to use Spring Boot, see [Using Vaadin with Spring MVC](https://vaadin.com/docs/v14/flow/integrations/spring/tutorial-spring-basic-mvc.md) to learn how to use Vaadin in a more traditional [Spring MVC](https://docs.spring.io/spring/docs/current/spring-framework-reference/web.html) web application.

## <a id="adding-dependencies"></a>Adding Dependencies

Like many other tech stacks on Spring Boot, Vaadin provides a starter dependency that provides all essential modules and auto-configuration. Only the `vaadin-spring-boot-starter` dependency is needed, but it is suggested to also declare `vaadin-bom` if you need additional Vaadin dependencies. For production builds, it is also suggested to add `vaadin-maven-plugin`, which generates the optimized JavaScript packages.

The following example shows Vaadin Spring Boot dependencies in `pom.xml`:

`pom.xml`

```xml
<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>com.vaadin</groupId>
            <artifactId>vaadin-bom</artifactId>
            <!-- Declare the latest Vaadin version
                 as a property or directly here -->
            <version>${vaadin.version}</version> <!-- <1> -->
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

<dependencies>
    <dependency>
        <groupId>com.vaadin</groupId>
        <artifactId>
            vaadin-spring-boot-starter
        </artifactId>
        <version>${vaadin.version}</version>
    </dependency>
</dependencies>
<build>
    <plugins>
        <!-- The Spring Boot Maven plugin for easy
             execution from CLI and packaging -->
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>
                spring-boot-maven-plugin
            </artifactId>
        </plugin>

        <!--
            Takes care of synchronizing java
            dependencies and imports in package.json and
            main.js files. It also creates
            webpack.config.js if does not exist yet.
        -->
        <plugin>
            <groupId>com.vaadin</groupId>
            <artifactId>vaadin-maven-plugin</artifactId>
            <version>${vaadin.version}</version>
            <executions>
                <execution>
                    <goals>
                        <goal>prepare-frontend</goal>
                        <goal>build-frontend</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
```

1. Notice that the `vaadin-bom` dependency in the `dependencyManagement` section declares the versions of modules in current Vaadin release.

## <a id="running-spring-boot-applications"></a>Running Spring Boot Applications

Spring Boot applications are executed through the traditional `main()` method. If Vaadin Spring dependency is on your classpath, Spring Boot automatically starts a web server and configures Vaadin with Spring. If you created your project at `start.vaadin.com` or `start.spring.io`, an application class with the `main()` method is already available to you.

The following example shows a minimal implementation of the `Application` class:

```java
@SpringBootApplication // (1)
public class Application {
	public static void main(String[] args) {
		SpringApplication.run(Application.class, args);
	}
}
```

1. The `@SpringBootApplication` annotation enables Spring Boot under the hood. This includes Spring configuration, component scanning and auto-configuration.

If you want to deploy your Spring Boot application as a traditional WAR file, follow the instructions in [Spring Boot documentation](https://docs.spring.io/spring-boot/docs/current/reference/html/howto-traditional-deployment.html).

## <a id="add-vaadin-view-to-spring-boot-application"></a>Add Vaadin View to Spring Boot application

In Vaadin Flow, a view is defined as a composite component. The Java class is annotated with the `@Route` annotation. The routes are detected at the application start and published in a path derived from the class name or defined as a parameter to the annotation.

The following example shows typical a main view of an application with the root route:

```java
@Route
public class MainView extends VerticalLayout {

	public MainView() {
		add(new Text("Welcome to MainView."));
	}

}
```

If you omit the path parameter from `@Route`, the framework derives the path from the class name. The derived name will be in lower case, and a possible trailing "View" will be removed. Also, the class names `MainView` and `Main` are mapped to root path (the path will be `""`).

## <a id="examples-of-using-vaadin-spring-boot"></a>Examples of Using Vaadin Spring Boot

[Vaadin Spring Examples](https://github.com/vaadin/flow-spring-examples) is an example application that showcases basic usage of Vaadin and Spring Boot. You can use it to test the concepts and features covered in this documentation.

`8BAAC835-14AA-471A-9924-251D7502FB73`
