Spring Boot, a project of the Spring eco-system

Introduction

Spring boot is a new project in the Spring eco-system.

As its name suggests, Spring boot allows you to start a Spring project by simplifying all the configuration aspects that are usually boring. It has been designed to simplify the work of the developer using Spring without compromising the foundations of the framework.

The Spring framework could be considered as complex to implement, heavy (many components), with dependencies sometimes badly mastered, and, in the spirit, rather adapted to a use on application servers.

Spring boot for what purpose?

With Spring boot, Pivotal is in line with the current trend towards microservices, which are inherently compact, simple and inexpensive to deploy in cloud environments, which is precisely what application servers tend not to allow. The simplicity of configuration and the deployment options make it possible to meet this need while not breaking the Spring architecture.

Spring boot is therefore aimed at any developer or architect wishing to use Spring in their projects. Its philosophy means that it is naturally intended to be used for new projects and the need to migrate an old project to Spring boot does not necessarily make sense.

The main functions

  • Simplified Spring dependency management

The new management is done either by inheriting from a parent spring-boot pom, or by creating its own pom importing the spring-boot pom. Then, the dependencies are integrated via the notion of "starter" atifacts which contain a set of technical dependencies grouped by function (e.g. spring-boot-starter-data-elasticsearch, spring-boot-starter-integration, spring-boot-starter-security, spring-boot-starter-web ...).
This way of managing dependencies avoids having long poms while letting Spring maintain the consistency of components during its version upgrades.

  • Easier deployment

A maven plugin gives the possibility to generate an executable jar easily in order to make your application an executable microservice by a simple java command.

  • From automatic configuration

This is one of the main features of Spring boot: a whole automatic configuration exists by default in the project to avoid the developer having to make trivial configuration statements. Some annotations on the main class (@EnableAutoConfiguration for example) allow to use this default configuration which acts according to the detection of the presence or absence of such class or such bean in the project.
This aspect is quite "magical" and it becomes possible to create a functional project quickly with very few lines of code.
It is clear that Spring is moving away from xml configuration to focus on configuration via java classes and Spring boot still provides additional annotations to avoid redundancy of some annotations.

  • More readable configuration of external properties

It is possible to use the yaml in the properties to be injected, which increases their legibility.
Similarly, the mapping between the configuration file and the java class becomes completely transparent by using a @ConfigurationProperties

  • Facilities for creating repositories

There are starters that manage dependencies for mongodb, neo4j, elasticsearch, ... and automated configurations for these systems.
Making a simple project integrating a secure web service storing data in a mongodb database becomes very fast and involves very few declarations.

  • Multiple possibilities to declare json outputs
  • Resource exposure via REST just with annotation

The automatic configuration included in Spring Boot contains the minimum to expose a RestFul API quickly

  • A powerful CLI (Command Line Interface) tool

This is another major feature of Spring Boot to enable rapid application prototyping.
The CLI allows you to run Groovy scripts from the command line while taking advantage of the automated configuration capabilities provided by Spring Boot.
Example of a web server creation via the CLI:

      • a "web.groovy" script

@Controller
class Example {
    @Autowired
    private MyService myService;
    @RequestMapping("/")
    @ResponseBody
    public String helloWorld() {
     return myService.sayWorld();
    }
}
@Service
class MyService {
    public String sayWorld() {
     return "World!";
    }
}
      • a CLI command: > spring run web.groovy
  • An "actuator" module dedicated to production metrics

This module exposes via a Rest API the autoconfiguration elements, the instantiated beans, the properties, the environment variables, the metrics on the JVM or on the health of the project, the possibility of remotely shutting down the application, the retrieval of traces or dumps... It is possible to extend or restrict the exposed services as needed.
This module is particularly interesting for deployment in production where it allows to see precisely what data is used by the application but it also allows to detect quickly during the development any configuration problems.

Conclusion

I was really convinced by Spring Boot (and Spring 4 at the same time) which brings a lot of productivity gains.

The concept is not to migrate an old project to Spring Boot nor to impose a development straitjacket but rather to use Spring Boot and its recommendations to build a Spring project from scratch.

The main drawback of Spring Boot is its very essence: it hides a lot of configuration and therefore does not always allow to understand how to overload with your own configuration. It is therefore necessary to understand first how Spring Boot works (by not hesitating to go through the source code and in particular the spring-boot-autoconfigure module) to get the best out of it.

A project in mind with this technology?


Contact us!

Talk to our dev?


Contact him!

Are you interested in this topic?

CONTACT US