First Spring Boot Tutorial
First Spring Boot Tutorial
In this series, we will introduce you to Spring Boot. As part of the series, we are starting with your first Spring Boot tutorial. Since it covers basics of Spring Boot, so feel free to skip this section if you already have a lot of experience in this. Here we will also cover Spring Boot basics, its different goals, and important features. We will start with Spring Boot initializer to understand the magic to set up a new project. We’ll also cover basic configuration and then will make our hands dirty with some basic projects. We’ll also try to understand what is a Boot actuator and cover some of the Boot tools.
Now, the question comes what is Spring Boot and how does it help you in programming. In this blog, we’ll try to cover this with an example along with few more questions a novice developer might have
What you’ll learn
- ✓ What is the Spring Boot?
✓ What are Spring Boot annotations?
✓ Where can I find some CRUD examples developed with Spring Boot?
✓ What problem does Spring Boot really solve?
What is Spring Boot?
Spring Boot is a framework which is built on top of the Spring framework. It allows developers to create production-ready applications very quickly. By using Spring Boot framework you can easily avoid your efforts in XML configurations, server setting, adding dependencies, etc. Also, since Spring Boot comes with the inbuilt server, we no longer have to use any external servers like Tomcat, and so don’t need to deploy WAR files. A real-time production ready application can really be created within minutes.
Spring Boot Example
Spring Boot enables you to quickly build applications. The other important goal is to provide all the common non-functional features. embedded servers, metrics health checks, and externalized configuration. Let’s understand this with the help of an example. Let’s say we want to develop a web application based on Spring MVC, which would additionally require Spring Core, logging, validation framework. Also, we’ll need some kind of configuration for all of these frameworks to work together. For example, if I’m using Spring MVC, I would need to configure dispatcher servlet, view resolver and a lot of things like that. However, with Spring Boot starter project it becomes very easy. All that you need to do is to add a starter called Spring boot starter web into your project and that’s it. You’ll get to Spring MVC for free. You get Spring core for free. You get a validation framework for free and also a logging framework for free.
Similarly, for JPA there is a starter called Spring Boot starter JPA. Once we use this starter. You would not only get JPA but also a default implementation of JPA with Hibernate and also auto-configuration of that. So you would not need to worry about the framework part and you can directly start creating your entities.
Another important feature we already talked about is embedded servers. Let’s say I am developing a web application I would want to deploy it on to a Linux box. In the olden days, the way it used to work is first I would need to install the Linux box. Then I would install java on it and then I would need to install a web server. So I would need to install either Tomcat, WebLogic or WebSphere and then I would take my application war and deploy it. This is the usual way we use to deploy stuff. We have a concept called embedded servers used with Spring Boot. What you can do is you can package your server. Thus you can package Tomcat along with your application jar. So I can include the Tomcat server in my application jar and I don’t have to install it on the Linux box. So all that I need to do, on the Linux box is if I have Java installed that’s sufficient. I can go ahead and run my application. I don’t need any other server installed on the Linux box. In the world of Microservices, this makes a huge difference.
Spring Boot advantages
Boot framework provides a number of production ready features. Spring Boot provides monitoring for your application through something called Spring Boot actuator. For example, you can find out how many times a particular service is called. You can find out how many times a particular service failed and also you can check whether the application is up and running or not. All these features come built in.
Another important feature that Spring Boot provides is externalized configuration. The configuration of applications varies between different environments. Your configuration from dev different from your configuration in production. Spring Boot provides these features built in. You can simply create property files matching a simple naming convention and that’s it. You’re ready with externalized configuration. Spring Boot also provides support for different profiles. These are some of the important goals and features of Spring Boot. The idea behind this step is to understand the big picture of Spring Boot. What it is, what it is not and what are the important features. In the next steps, we will dig deeper into each one of these things.
Spring Boot and Micro Services
In last few years Spring Boot has grown very rapidly. It is now the goto framework to create micro services – a well known trend these days, which ensures that instead of building a huge monolithic application we divide the functions in smaller subparts called micro services. So, instead of one large application we might have 10-20 micro services. Important thing to remember here is that you need to develop these micro services very rapidly – frameworks like Spring Boot help you to achieve this.
What not to expect from Spring Boot?
Before we proceed further, lets see what not to expect from Spring Boot. First thing is – its not a code generation tool as there’s no code generated additionally at all – a distinguising feature for Boot. The other thing is that its not a web server. Boot integrates well with the embedded servers for example Jetty, Tomcat etc, but that doesnt mean that Boot itself is a web or application server.
In the article above we heard about few key terms while learning about Spring Boot. Lets try to cover a short description about them as well.
Instead of creating a large application or monolith, we can divide the application into smaller parts called microservices. Each microservice is an independent entity in itself. We will cover microservices in great detail in one of the coming sections and share the link here.
Related interview questions
Here’s a list of other related questions on this topic that could be asked in technical interviews –
- What is the Spring Boot? Is this a new technology or toolset?
- What problem does Boot solve for you?
- What is new with Spring Boot 2.0?
In this article we went through a quick Spring Boot tutorial explaining the very basic of the framework and the problems its trying to solve. We’ll try to add more articles in this series in coming days.
Please feel free to ask your questions in the comments section and let us know if you feel the article has helped you in understanding the First Spring Boot Tutorial concept better.
Below link could be a starter for you in your journey to learn Spring Boot.
Was this page helpful? Please use the commenting form below to ask any questions or to make a comment. Please do not put the same comment multiple times. Your comment will appear after some time. Also please note that we do not reply to emails or comments on social media. So if you have any question, please put it in the form below and we will try to reply to it as soon as possible. We usually reply within a day.
Leave a Reply