Choosing Spring Boot as part of your stack

I have been developing in Java for the last 6, 7 years and I have seen lot of changes. Have followed Spring framework since version 1 and I have to say I am really impressed in relation to what they are achieving. Some years ago I had a look to Spring Roo, a RAD tool for creating web applications. At that time, I learnt a lot about web development and best practices but things were changing towards API centered applications and javascript apps (as clients).

Spring IO platform

Spring IO platform

I ended up abandoning the project as it was difficult to modify things by yourself apart from the fact of modifying jsp on the views and having to redeploy heavy processes on the server in order to reflect the latest changes.

About a year ago, I started using Spring Boot. It was mainly curiosity in order to see what the guys were doing. I got in love with the flexibility and out of the box solutions it provided. In the following lines I will go through some of the features I really liked and that I incorporate now on all my projects.

Spring Actuator

Actuator is just a solution for production apps. Normally use on devops as we can get several metrics and send them to other systems to keep track of the health and kpis of our applications. Endpoints like bean management, health status, metrics exposure come with it.

The actuator artifact let us do some calls like:

Health status
http://localhost:9001/health

Metrics exposure

http://localhost:9001/metrics

Bean mappings exposure

http://localhost:9001/mappings

It is also good to know that the port for the management endpoints can be changed to the default listening port so they don’t get exposed to the public.

Spring Rest

Create endpoints is really easy and fast. As soon as you know what you want to do and get familiarized with the annotations, you will not want to go back to writing endpoints in the ‘hard way’. Writing a controller is as easy as:

Spring async

Is your application a middleware connecting with some external sources and want to continue running code until the response is back? Spring does it really easy with the @Async annotation (* You would need to use @EnableAsync on your @Configuration file)

An example is:

That’s all, you have a really clean solution of setting background work on a new thread and you can capture the information back with the Future#get() method. This, in my opinion is a really clean and neat way of letting devs to choose sync or async operations. I normally use this for connecting to remote services and perform other actions in the meantime.

Spring caching

Following the example of async, something that comes into play with external sources or heavy processes is the caching mechanism. Normally you can store the information in a variable and check for retention policies:

All this looked to me in the past pretty hacky and the use of an abstraction for caching results is something you can do pretty easy on a spring boot app. This helps you to change cache abstractions in the future and to rely on other technologies.

On spring, you can use @Cacheable (on the method) and @EnableCaching on your @Configuration file

Example:

Spring data

Access to db in a jdbc or jpa way , as well as indexing and retrieving results from a ElasticSearch instance is something extremely easy to do.

On JPA, we just need to add @EnableJpaRepositories to the @Configuration file and create our repository layer:

Similar way for solr documents, elastic search documents, Redis objects …

Summary

  • Spring boot is a tool that let the developer to program concise programs providing an out of the box solution for exposing metrics, endpoints…
  • As applications nowadays are api centered, Spring boot is a really good tool to prototyping and even take it into production. No long hours and headaches, we could have an api service running on PaaS in a matter of minutes.
  • Actuator, Async and Caching are solutions that integrate really well with Spring Boot. Highly recommend them to be part of your prototypes as well.
  • I normally start with this project and work on whatever I need. Maybe I move this to an maven archetype in the future if someone is interested. Also Spring Initializr is a good way to start a project.

6 thoughts on “Choosing Spring Boot as part of your stack

  • Everything said made a great deal of sense. But, think about this,
    suppose you typed a catchier post title? I mean, I don’t want to
    tell you how to run your blog, however suppose you added something to possibly grab a person’s attention? I mean Spring boot applications | Jose David Baena
    is kinda vanilla. You should look at Yahoo’s home page and note how they create news titles to grab people interested.
    You might add a related video or a related picture or two to grab people interested about everything’ve written. In my opinion, it could bring your posts a little livelier.

    • Sure! Thanks for the feedback 🙂
      Will have this in mind for future posts and see how i can improve this one in the following days.
      Agree with you it is not the catchier, I certainly lack on promotion and presentation.
      Thanks for taking the time in answering with such a constructive feedback

Leave a Reply

Your email address will not be published. Required fields are marked *