Spring has been a great framework for years however it had few drawbacks. In this tutorial, An Introduction to Spring Boot we will see how Spring Boot has not only addressed the drawbacks but also supports modern software architecture. Spring Boot is around for sometime now, I had started working using spring boot 1.5 years ago, now at the time of writing this article the latest version is 1.3.3. This tutorial would provide an introduction to Spring Boot and also how you how to get started with it.
Why Spring Boot ?
Even though Spring is a great framework it has few pitfalls. Spring Boot was build not just to address them, it also provides direction to the future of software development. Spring’s XML based configuration is a nightmare in the world of annotation. There was no clear leader in the java framework world to support Microservices. You really don’t want different teams building Microservices to adapt different set of Java Libraries and look very different to each other.
What Spring Boot brings to the table ?
Convention over configuration
Spring Boot has taken away all the XML based configurations and provided Annotations for using the Spring Framework. You can start your application with a very minimum annotation in no time. This would be very helpful to the developers, the team productivity would greatly be impacted positively.
Standardization for Microservices
One of the main objective of Spring Boot is to provide a unified ecosystem of libraries & standards to all the developers (teams) utilizing Microservices methodologies. Any project adapting Microservices would have multiple teams and we certainly don’t want each of team to build the softwares in very different way. The teams will be also benefit from the all the annotation and tooling Spring Boot brings, however it also provides-
- A common platform and library support
- Reduced setup, configuration time in development environment.
- Cloud Support
Integrated Server for Development
Spring Boot attaches a Tomcat/Jetty server with the compiled Jar using Maven/Gradle. This helps the developers to expedite the development process by using the integrated server. In 2-3 mins you could build & test a RESTful web service from scratch.
Cloud Support
Spring Boot provides cloud support for configuration, tools and clients. It’s also compatible with Cloud Native and works seamlessly with Cloud Foundry, Pivotal etc.
Adapt & Support for 3rd Party Library
Spring Boot has taken a significant step and widen support for 3rd Party Open Source Library like Netflix OSS, No-SQL DB, Distributed Cache etc. You will find a full list in the Spring Boot home page, however the seamless integration using Annotation is very powerful.
What is Spring Boot ?
In one sentence, Spring Boot is equal to ( Spring Framework – XML Configuration ) + Integrated Server.
Spring Boot Components
Spring Boot Auto Configure
Module to auto configure a wide range of Spring projects. It will detect availability of certain frameworks (Spring Batch, Spring Data JPA, Hibernate, JDBC). When detected it will try to auto configure that framework with some sensible defaults, which in general can be overridden by configuration in an application.properties/yml file.
Spring Boot Core
The base for other modules, but it also provides some functionality that can be used on its own, eg. using command line arguments and YAML files as Spring Environment property sources and automatically binding environment properties to Spring bean properties (with validation).
Spring Boot CLI
A command line interface, based on ruby, to start/stop spring boot created applications.
Spring Boot Actuator
This project, when added, will enable certain enterprise features (Security, Metrics, Default Error pages) to your application. As the auto configure module it uses auto detection to detect certain frameworks/features of your application.For an example, you can see all the REST Services defined in a web application using Actuator.
Spring Boot Starters
Different quick start projects to include as a dependency in your maven or gradle build file. It will have the needed dependencies for that type of application. Currently there are many starter projects (We will learn about few of them in the next section) and many more are expected to be added.
Spring Boot Tools
The Maven and Gradle build tool as well as the custom Spring Boot Loader (used in the single executable jar/war) is included in this project.
Spring Boot Starters
Spring Boot incorporates many starters packages (in Maven & Gradle) which you can include in order to add appropriate support in your project. At a high-level there are so far 6 types of starters packages available. You can find all of them in Spring Boot official WebSite.
How to use Spring Boot
In another post we will see how to use and run Spring Boot, however here are the steps you need to follow.
- You can use spring initialize to create the initial setup. You can visit either start.spring.io or use STS (Spring Tool Suite) Support available in IDEA or Eclipse to choose all the Spring Boot Starters
- You need to also choose whether to use Maven or Gradle as the build tool.
- If you are using start.spring.io, you need to then download the zip and configure your workspace. Otherwise using your preferred IDE will automatically create the required file in the workspace.
- Add your code as required
- You can either use
mvn clean package
or use IDEA or Eclipse to build and create the jar file. - By default the JAR would include integrated Tomcat server, so just by executing the JAR you should be able to use your program.
Disadvantages of Spring Boot
Migration Efforts
Migration from already existing spring project to spring boot is not straightforward. Spring Boot is mostly for new development project.
Deployment to WebSphere/WebLogic Servers
Deploying Spring Boot application to WebSphere/WebLogic Servers are also not very simple. You need to make few changes like downgrading JPA Version, remove conflicting Jars etc in order to make it work in WebSphere/WebLogic Application Server.
Microservices & Cloud Native
Spring Boot has been developed keeping Microservices & Cloud Native in mind. You may not see improvements in other areas.
Conclusion
Hopefully this article provided you an introduction to Spring Boot. This should get you started with Spring Boot, I will have more articles posted on Spring Boot and Microservices soon.
This post is the 1st part of Getting Started with Spring Boot Series. Find all the parts here.
- An Introduction to Spring Boot
- How to Create Spring Boot Application Step by Step
- How to create RESTFul Webservices using Spring Boot
- How to deploy Spring Boot application in IBM Liberty and WAS 8.5
Chandra Sharma says
Nice Article,
I got Clear picture about Spring Boot after Sping complex xml configurations.
Thanks!!
A Developer Diary says
Hi Chandra,
Thanks for your feedback ! Glad to hear that this has helped you.
Thanks,
A Developer Diary
Saurabh Gandhi says
Very Nice Article.
Will highly recommend this article.
Keep up the good work.
Best Regards,
Saurabh Gandhi
Due Nguyen says
Thanks for the great tutorial, I found also one tutorial to share that has the source code ready: How to build a full hashtag messaging API with Spring boot and JPA
http://weall.com/book/chapter?name=Download%20Messaging%20application%20using%20Hashstag%20Component%20Tutorial
VINOD says
Nice article, at least we know that what is Spring Boot and its advantages and disadvantages.
Amit Jain says
Useful article. Displays clear picture of Spring Boot.
Mehraj Malik says
Nice explanation.
Keep it up.
Cesar Calderon says
Great article! I’m trying to learn Spring and I found this article as a great starting point.
Siddu says
am executing spring boot examples but I am getting below error.
Error: Could not find or load main class com.accenture.SpringCloudEurekaDemo1Application