Creating a Simple Spring Boot and Vue.js Project



Spring Boot allows Java developers to rapidly assemble sophisticated RESTful web services, it normalizes access to a myriad of different SQL or NoSQL databases and provides all the necessary controls to secure a web application.

Many developers don’t want to utilize older solutions such as JSP, nor do they want to commit to the complexity of a fully-fledged front-end framework such as React or Angular. Vue.js provides for a fantastically modern shift in terms of how a reactive Javascript framework can be adopted and integrated into your Java application.

In this article, I’ll cover the steps needed to create a simple hello world web application using Spring Boot 2.4 and Vue.JS 2.


You will need the following:

  • An IDE of your choice (Idea IntelliJ or Eclipse are preferred)
  • Java Development Kit (JDK) and Java Runtime of Java 8 or greater (Open JDK is preferred)
  • Maven installation

Getting Started

In your Maven project’s pom.xml file, the following is how to define the dependencies:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="" xmlns:xsi=""
    <description>Demo project for Spring Boot</description>






Within your src/main/resources/static folder, create a js folder and drop in your vue.js script files. These vue files can be found at the following:

Please refer to the following image to confirm your project structure is the same:

VueJS and Spring Boot project folder structure

Vue Application Code

Create an empty app.js file in your js folder and add the following code:

var app = new Vue({
  el: '#app',
  data: {
    message: 'Hello world from Vue and Spring!'

This code initializes a new instance of Vue and defines a variable within Vue called message. By updating this variable within your application code, your application’s webpage DOM will reactively be updated.

The reference to #app is the ID of the div in which we want Vue to bind to and make reactive. It is possible to also bind to a body tag or even the html tag.

Vue Web Template

In your templates folder, create an empty index.html file and add the following code:

<!doctype html>
<html xmlns="" xmlns:th="">
    <title>Hello world example from</title>
  <!-- This div is where all of the Vue magic will happen! -->
    <div id="app">
      {{ message }}
    <script th:src="@{/js/vue.js}"></script>
    <script th:src="@{/js/app.js}"></script>

Note the {{}} mustache style brackets in the above code. These symbolics inform Vue that this is a variable in which you want to reactively update within the page.

This template is using Thymeleaf to automatically derive the correct context paths of your static resources vue.js and app.js.

Spring Configuration

Add the following properties to your file:

# Defines your application's context path when it is run in the application server
# Configures Spring Boot to add various mappings for your static files

Define your Spring Boot main class:

package com.codetinkering.example;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
public class ExampleApplication extends SpringBootServletInitializer {
    public static void main(String[] args) {, args);
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
        return builder.sources(ExampleApplication.class);

Your final project structure should look like this:

VueJS and Spring Boot project folder structure

Running your application

Start your application by running the Spring Boot main class via your IDE or execute it via Maven via the following:

mvn spring-boot:run

Your application should be accessible at http://localhost:8080/example/

Upon accessing your application, you will see a hello world message (which is reactively rendered to the screen):

Screenshot of Vue hello world in browser

Checkout this project from Github

git clone
Download Zip