Java Web Application Starter Template with Spring Boot

Every now and then a developer or team has to work on new web projects, proof of concepts etc. For this they have to create project from scratch and configure it for database connection, security. I am putting together a started Java Web Application project that anyone can use and build on top of it.

Software used in this sample

You can download the code from Opencodez Git Repository

To get rid of all the boilerplate coding, we are using Spring Boot here to manage all our core dependencies. We will add dependencies for MySQL and C3P0 for better pooling. This is our basic properties file with some global parameters

This is a web application so we may have to use css, javascipt. For this we will be using Bootstrap and Jquery. In order to maintain versioning we will use WebJars to provide us versioned bootstrap and jquery js and css files. The dependencies in pom file will look like

The application will have main navigation and one secured navigation. For Security for now we will use in memory authentication with sample user and password. Below is java web application security configuration class.

You can see that we are using custom login and logout handlers. We did that so that we can have more control on how user is redirected once he is authenticated. For starter java web application we have simple checked if the user is authenticated or not. But for more advanced need you can put in role based redirection as well.

As an addition to our starter project template, we have added an useful interceptor for java request handlers. This handler will make available the controller name and action name in the view. This information can be used in various ways. In our example, we are using it to highlight active links.

and this will be added to our configuration as

Regarding thymeleaf you can see below the resource structure

Java Web Application - Resources

Java Web Application – Resources

We have divided the and made template using common parts of any webpage like header, footer, scripts. You will be able to download the complete code from our github repository.

Once setup and run you will see pages like below

Java Web Application Home Page

Login Page

Home page after login

Hope this starter project helps many. Please let me know if you have any queries.

2 Comments
  1. May 17, 2018 | Reply
    • Shilpa
      May 17, 2018 | Reply

Add a Comment

Your email address will not be published. Required fields are marked *