Image Image Image Image Image Image Image Image Image Image

Mudassir Shahzad | March 26, 2019

Scroll to top


No Comments

Why use Spring Boot rather than Spring Boot-less?

Why use Spring Boot rather than Spring Boot-less?
Mudassir Shahzad

When people say, “Spring Boot does everything”, it’s not clear what “everything” is.

If you are a java developer, there is a high probability that you have heard about spring or even used it in a few of your projects. Spring framework was created primarily as a Dependency Injection container but it is much more than that.

You’re probably thinking, COME ON, I came here to read about spring boot not spring. Well, bare with me you angry human. This is very easy, so let me explain. *Turns face towards the board*

Right now, Spring is the de-facto standard framework for Java-based development, especially in corporate environments. Usually when we talk about Spring, we’re talking about web development using Spring MVC. While Spring is still hugely popular, in recent years we’ve seen a number of lighter, simpler frameworks *ahem* spring up that can make simple web development much quicker and easier. So, is Spring on its way out?

Unfortunately, along with Spring’s flexibility comes a fair amount of complexity. Spring tends to need quite a bit of configuration just to get to a workable state (and this used to be stored primarily in *shudder* XML), so the task of starting a new Spring application from scratch (and then maintaining it) can seem daunting. Spring has made some strides over the years as far as ease of development, including adding annotations which replaced more-and-more XML config over time. For a while now, it’s even been possible to create a Spring application without any XML at all. But, even at a basic level, you’re probably going to want a web app with a templating framework for your HTML pages, a database for persistence and some security. With just these components – and likely more to configure – you may end up a couple days into a project with nothing to show for it except a shell of an application that hopefully starts without crashing.

This is where Spring Boot comes in. Spring Boot can take almost all of the hassle out of this normally arduous process. It essentially takes Spring and sprinkles in some opinions about how things should be done. With Spring Boot, there are a plethora of pre-configured components with sane defaults that can be added without breaking a sweat.

For example, using Gradle, we’ll start a project by adding the spring-boot plugin and a dependency on spring-boot-starter-web to our build config.

Then we’ll just add a one-liner main method to kick things off.

Then, … wait, that’s it? Pretty much! But let’s go ahead and add a controller to actually make something happen.

There, we’ve got ourselves a working REST application!

But I need all the things! If you want to use a fancy templating library like Velocity or Thymeleaf, just add a single dependency and Spring Boot will set it up with a sensible default configuration. How about persistence? Again, a single dependency will enhance your project, this time with a pre-configured HSQL implementation. Don’t want to use HSQL in production? Add a dependency on the database of your choice and a couple of application properties to define your data source. You can even automatically build up Spring security with a default configuration offering simple password authentication.

Just a couple of change are required to add all of that.

The cherry on top is that running applications is also easier with Spring Boot. It will compile all your dependencies into one runnable jar, complete with an embedded tomcat servlet container. Of course, you can easily specify a different servlet container by adding it as a dependency, or you can just package your app into a war file for deployment in a more traditional manner.

Spring Boot gives you a super easy way to get started with some default settings, along side many of the newer frameworks out there, but also affords you all the same configurability you would have in any other Spring project. Whether you’re doing something as simple as changing your template filename pattern from *.html to *.mustache, or as crazy as implementing a brand new security paradigm, Spring Boot will let you make the changes you want, and then intelligently fill in the gaps – but only where you haven’t specified your own configuration. This is what really makes Spring Boot a welcome upgrade. It can be as simple or as custom as you want it to be. It’s not always the right tool for the job, but it’s definitely worth consideration when planning new projects.



Submit a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.