Architecture & DesignUnderstanding Spring Boot Starters and Tools

Understanding Spring Boot Starters and Tools

Developer.com content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More.

Spring Boot simplified Spring application development. The tools it provides reduce development time considerably. No more hunting for dependencies, the starters provided by Spring simplified it by following the idea of convention rather than configuration and can help build almost any type of project specification quickly. The starters and the developer tools provide the vital strength in building Spring boot application. This article takes on a few of the popular ones among many and describe their uses in developing a Spring Boot application.

Overview

The Spring framework has established itself as a de facto standard for developing almost any type of Java application down the years. One of the biggest complaints about Spring was that it has to be configured properly to work in a seamless manner. Also, there are numerous dependent libraries that comes in jars. These jars form a crucial part to make Spring framework to function properly. Developers give them a close eye to make sure what the dependent jars are, their matched version, and so forth. In a nutshell, it was very easy to be lost in the configuration and dependency issues.

Spring Boot provided a game-changing scenario by offering a new paradigm for developing Spring applications with almost no friction. Because Spring Boot takes care of the configuration and dependency issues, developers can focus on an application’s business functionality with almost no intervention in the configuration and dependency drama.

The magic that is applied by Spring Boot to Spring application development is as follows:

  • Automatic configuration: It automatically takes care of the application configuration issues on behalf of the developer. Most application have a common configuration pattern which, when automatically provided, can greatly help the developer. Of course, there are options for overriding the configuration if need arises. In practice, such need does not occur very often.
  • Starters: The starters provide the required dependencies needed for the build according to the type of project chosen. For example, a Web project has certain dependencies that may be included simply by stating a “Web project.”
  • Command-line interface (CLI): With Spring Boot, an entire application can be written using application code. The optional CLI feature empowers it to run the application without a traditional project build.
  • Actuator: This enables developers to peek into a running Spring Boot application.

The real magic of Spring Boot lies in leveraging …conditional configuration features from Spring 4, along with transitive dependency resolution offered by Maven and Gradle, to automatically configure beans in the Spring application context… (Spring Boot in Action—Craig Walls).

Developer Tools

The developer tools provided by Spring Boot enhance the convenience of application development. For example, the spring-boot-devtools module may be included in any project. It makes it easier to work with Spring Boot at development time. The developer tools come in the form of a library that gets plugged into the project dependency. It, however, gets disabled when the application is running from a packaged JAR or WAR file. It makes no sense to include them in production deployment because they are required only during development phases.

A Maven include of devtools is as follows:

<dependencies>
   <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-devtools</artifactId>
      <optional>true</optional>
   </dependency>
</dependencies>

In Gradle, it is as follows:

dependencies {
   compile("org.springframework.boot:spring-boot-devtools")
}

The capabilities provided are as follows:

  • It automatically restarts a running application as soon as any change is made in the files situated in the classpath. The developer need not restart the application to reflect changes made in the code. It saves lot of the developer’s time.
  • The automatic change in the code not only restarts the application but also refreshes the browser automatically.
  • When developing remotely, the automatic restart and refreshes are also done accordingly.
  • The configuration properties are set with default values without developer intervention. As a result, a developer can quickly run the application to see what it takes with default values.

Starters

A project’s dependencies are taken care of by the starters. It does so by aggregating commonly used dependencies under a banner with a name for it. The developer names it in the dependency section of their project and the build specification transitively resolves the required dependencies issues. Forget about those days when crude dependencies were a pile of jars include in the Maven or Gradle. Starters organize the dependencies under a named banner which makes the dependency specification small and neat. For example, rather than specifying all the dependent jars for, say, Hibernate Validator and Tomcat’s embedded expression language, we can simply add the spring-boot-starter-validation starter. That’s all. All the required dependencies are automatically imported under that banner.

There are many starters available. Here are just six of them to get a glimpse. Refer to Spring Boot application starters for more.

Starter Transitive dependency Description
spring-boot-starter spring-boot, spring-boot-autoconfigure, spring-boot-starter-logging, spring-core, snakeyaml Core starter, autoconfiguration support, logging, YAML
spring-boot-starter-batch Spring-boot-starter, hsqldb, spring-jdbc, spring-batch-core Starter for using spring batch
spring-boot-starter-data-jpa Spring-boot-starter, spring-boot-starter-aop, spring-boot-starter-jdbc, hibernate-entitymanager, javax.transaction-api, spring-data-jpa, spring-aspects Starter for using spring data JPA with Hibernate
spring-boot-starter-test Junit, mockito-core, hamcrest-core, hamcrest-library, spring-core, spring-test Starter for testing using libraries Junit, Hamcrest, Mockito
spring-boot-starter-web Spring-boot-starter, spring-boot-starter-tomcat, spring-boot-starter-validation, jackson-databind, spring-web, spring-webmvc Starter for building Web application using Spring MVC, REST, Tomcat as a default embedded container
spring-boot-starter-data-mongodb Spring-boot-starter, mongo-java-driver, spring-data-mongodb Starter for using MongoDB and Spring data MongoDB

Conclusion

The developer tools and starters are the flagship feature of developing a Spring application with Spring Boot. Spring Boot has taken over the conventional Spring application development techniques. Rarely, one needs to stoop down to the old system of Spring development. Spring Boot provides almost all of the developer’s needs, especially in the arena of automatic configuration, dependency management, and ease of development.

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends & analysis

Latest Posts

Related Stories