This interview is an excerpt from The Confident Spring Professional course.
Simon Martinelli is a passionate Java, software modernization and application integration expert with more than 25 years' experience as a developer, architect, and technical lead.
An active member of the Java community process, he has made contributions to JSR-352 Batch Applications, JSR-354 Money and Currency API. Since 2007 he has been an Adjunct Professor at Berne University of Applied Science in Switzerland and is teaching architecture and design of distributed systems and persistence technologies.
Marco: Hi Simon! Since when do you program with Spring and how did you get into it? Do you still remember your very first Spring project?
Simon: It was in 2005 and I was working for Swiss Railways in a project for generating train routing data were I used Spring Framework for the first time.
The UI was built using Eclipse RCP and we had to deploy to IBM WebSphere. The main benefit of using Spring was the development speed.
Thanks to Spring we could run the backend embedded in the frontend during development. And the developers didn’t need to install WebSphere on their computers.
Also, the testability was much better because of the abstraction of the underlying runtime and the test configuration.
Marco: For people new to the Spring ecosystem, what Spring projects would you recommend having a look at and in which order? Why?
Simon: Today, for sure, the starting point is https://start.spring.io. Spring Boot makes it very easy to use the Spring platform in an opinionated way.
Opinionated means that there is a lot of useful default configuration for all libraries and frameworks where a Spring Boot starter exists. For example, if using Spring Data JDBC the datasource is auto-configured.
Data access is usually required in a business application. So you should start looking at Spring Data. Spring Data provides uniform access to many kind of data stores like SQL or NOSQL databases or search engines.
Then you need a UI. Today we either develop a SPA (single page application) with React, Angular etc. where we use a REST API or we want to render the HTML on the server side using a template engine.
Both can be implemented using Spring MVC. There is also Spring Webflux if you want to go reactive.
Marco: What would you say is the one thing where most developers go wrong with Spring?
Simon: Spring is 17 years old. New developers may think that the framework is old and heavy-weight. In the early days, Spring needed a lot of XML configuration and it was often hard to find configuration errors.
But Spring did a decent job with introducing Spring Boot’s auto-configuration capabilities.
Often people think that Spring Boot is a microservice framework. But that’s just half of the truth.
You can build any kind of applications from Microservices to monolithic applications and integration and batch applications.
Marco: What project(s) would you recommend to build in order to get more practice with Spring?
Simon: The best project is to implement an application for something you know quite well.
For example, I’m helping to organize youth track and field events. Many years ago I wrote the first version to enter the results and to print ranking lists.
Over the years I implemented the exact same use cases several times each time with different technologies.
Today this application is open source and available online @ https://jtaf.io. And guess what - I’m already working on the next version with new technologies :-)
There is for sure a need for a small app in your community where you could try different technologies and make people (and you) happy.
In case you don’t find something useful, have a look at the Sakila database: https://dev.mysql.com/doc/sakila/en/
The business case is a DVD rental store (I know in the age of Netflix this may sound old school).
There is a data model and data that you can use to start.
Marco: Would you still invest time in learning Spring based on servlets and JDBC, or go straight into reactive Spring?
Simon: Reactive is the right tool for applications with a heavy load that need to scale and where the thread-based model comes to its limit.
In 25 years I’ve developed many business applications and only two of them fall in this category. Most of the applications were very specialized and had only a few sometimes a few hundred users.
Therefore I didn’t miss the reactive stack. And yes, you should also learn the thread-based model with servlets and JDBC. Very often this fits very well and is maybe the easier way.
Marco: With the advent of client-side frameworks (React, VueJS, Angular), what’s your take on writing web applications with server-side template rendering, like Thymeleaf? Is that now legacy?
Simon: Always use the tool that best fits the requirements. If you must build a highly interactive application SPA may be the answer. But if you create a form-based application a server-side rendering like MVC with Thymeleaf is the better fit. I would also recommend to have a look at Vaadin. I’m currently using Vaadin in a ERP UI replacement project and the development speed is impressive.
Keep in mind when choosing a client-side framework you will create what formerly was called a client/server-application.
You will have to learn a new language and a completely different build stack. Another important fact is that you will need a REST API that you also have to test.
Both will cost time and money.
Marco: What is your favorite way to connect your Spring application with a database? Would you recommend plain JPA? Hibernate? Spring Data? Any other of the 500 available choices?
Simon: I started using Toplink (now EclipseLink) 20 years ago. Later I mostly used Hibernate but I finally came to the conclusion that in many cases this abstraction layer doesn’t help. It just adds more complexity and hides the power of the underlying database.
Today I prefer using jOOQ where I have full control over SQL and can use all database features. For example, I can directly create JSON or XML from a SELECT statement without any additional mapping framework. Additionally, due to the jOOQ DSL and the object generator I can write compile time checked SQL.
There is a Spring Boot starter for jOOQ that auto-configures the datasource and adds transaction support.
Marco: There are some misconceptions that Java or Spring might be slow, bloated or simply too legacy. What do you think about other choices, like Micronaut, Quarkus or even other languages like Kotlin or Scala?
Simon: Spring is very mature and has embraced so many technologies and frameworks you will find a solution for every kind of application.
Micronaut and Quarkus are quite new but the startup time is impressive and also the fact that there is no reflection and you can build native images is great.
Spring is working on that too. I think it’s just a matter of time when Spring will catch up.
Both are great frameworks but not yet that feature-rich as Spring. As long as Micronaut or Quarkus cover all your requirements they work both. But if not be aware that you may need an additional framework to fill the gap and then you have to deal with two technologies.
On the language side I like Kotlin, it feels like a modern version Java. But also Java is getting more modern with
var, Records, switch expressions, pattern matching etc.
I think choosing the right language is something the team has to do. If you feel more comfortable with Java stay with it otherwise choose whatever works best for your team.
Marco: Is there something you would say that Spring could do better and needs some improvement?
Simon: Spring Security is very powerful but it’s also very complex. It would be great to further simplify the most common use cases.
Marco: What is the best way to follow you and learn more about your work and what you do?
From time to time I’m speaking at conferences or local meetups. (If you like to hear a talk about Spring Boot, Vaadin and jOOQ let me know :-)
Marco: Thank you, Simon!
There's more where that came from
I'll send you an update when I publish new guides. Absolutely no spam, ever. Unsubscribe anytime.
There's more where that came from
I'll send you an update whenever I publish a new guide.