An interview with Siva Prasad, author of 'Beginning Spring Boot 2' and 'Spring Boot - Learn By Example' on learning all things Spring: Spring Framework, Spring Boot & the Spring Ecosystem.
Marco: Hi Siva! Would you mind quickly introducing yourself?
Siva: Hi Marco. I am working as a Senior Software Engineer at a startup company in Hyderabad, India. I also wrote several books on Spring Boot, PrimeFaces & MyBatis. Simply put, I love learning new things and coding for fun.
Apart from technology, I like reading books and watching movies a lot.
Marco: Since when do you program with Spring and how did you get into it? Do you still remember your very first Spring project?
Siva: I started using Spring framework 1.x in 2007. We were mainly using Struts and Hibernate and thought of using Spring for a new project and I liked it a lot.
I remember the early days of Spring where we used to configure ProxyFactoryBean
, <tx:advice/>
, etc in XML :-)
The main reason for me to like Spring so much is Spring enables testing all layers without requiring to deploy the application in the application server.
Marco: For people new to the Spring ecosystem, what Spring projects would you recommend having a look at and in which order? Why?
Siva: I would strongly recommend reading and understanding the Dependency Injection, Front Controller, Factory and Template Design Patterns. Spring heavily uses these patterns, so being familiar with these patterns will help to learn Spring quickly.
I would strongly recommend starting with Spring Core concepts to understand various ways of configuring beans (@annotations, JavaConfig), bean life cycle methods, scopes etc.
Though Spring started as an IOC container, it’s much more than that. Spring provides abstractions for many of the commonly used libraries like JPA, JMS etc. Get to know how to use those abstractions and avoid boilerplate coding.
Talking about Spring without mentioning its amazing support for database transaction handling is impossible. Understand Spring’s annotation-based transaction handling, and how propagation and isolation levels work.
Finally, you can go on and learn Spring MVC, Spring Security, Spring Cloud etc. By now you might be wondering why I didn’t mention Spring Boot!!! Read my answer to the next question.
Marco: What would you say is the one thing where most developers go wrong with Spring?
Siva: One common mistake many people, who are new to Spring or even new to Java, do is directly jumping onto Spring Boot.
A newbie can build a Spring Boot application by simply following Spring Boot guides or any blog post without much struggle. But it all looks magical because they don’t know how and why it is working.
If a developer knows how to configure and use Spring without Spring Boot then it is very easy to understand how Spring Boot works.
Marco: What project(s) would you recommend to build in order to get more practice with Spring?
Siva: The pattern I followed and I recommend to newbies to learn Spring (or any framework) is as follows:
-
Create a lot of small applications to learn/practice specific features
-
Build small end-to-end applications like TodoList or a Blog that covers from front-end to back-end so that we can learn Web layer using SpringMVC, transaction handling at Service layer, Database integration using Spring Data JPA.
-
Build slightly more complex applications like a shopping cart which may involve building multiple modules, consuming 3rd party services, sending emails, scheduling jobs etc.
The key is to practice writing a lot of code, observe what can be improved, automate/abstract boilerplate code.
Marco: Would you still invest time in learning Spring based on servlets and JDBC, or go straight into reactive Spring?
Siva: Still 90% of the projects that I worked on are use SpringMVC, RDBMS using JPA/MyBatis/JooQ. I think Reactive Programming is still a niche technology and hasn’t been adopted widely especially in large enterprises. So, I strongly suggest learning servlets and JDBC which are the foundation for many of the frameworks.
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?
Siva: Personally I feel SPAs (Single Page Applications) are more suitable for internal applications. We can use React, VueJS, Angular for public-facing websites also but I don’t feel the amount of extra work that needs to be done for SEO, Server Side Rendering (SSR) is worth the trouble.
I prefer the middle ground where we can use server-side rendering technology like Thymeleaf and all the interactions within the page can be implemented using React or VueJS reactive components.
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?
Siva: For small to medium-sized projects I prefer to use Spring Data JPA. We can use JPA/Hibernate to work with even more complicated DB schemas also, but most of the time developers end up spending way too much time dealing with tricky ORM issues. I prefer to use SQL oriented frameworks like JooQ or MyBatis because they result in simpler and straight forward code.
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?
Siva: I guess many people stick with that opinion of "Java is slow and bloated" based on their EJB 1.x experience and never looked at recent versions of Java. I am very very happy and productive with Java 8+ and Spring Boot.
I haven’t actually used Micronaut or Quarkus in my real projects. Based on what I read, these frameworks provide hot code reloading, GraalVM Native image building capabilities which are really cool.
Marco: Is there something you would say that Spring could do better and needs some improvement?
Siva: Spring Cloud makes building microservices very easy. Though Spring Security provides a lot of features, still implementing OAuth based security for microservices is very challenging.
Marco: What is the best way to follow you and learn more about your work and what you do?
Siva: I blog about my learnings on http://sivalabs.in and you can follow me on Twitter @sivalabs.
Marco: Thank you, Siva!
There's more where that came from
I'll send you an update when I publish new guides. Absolutely no spam, ever. Unsubscribe anytime.
Comments
let mut author = ?
I'm @MarcoBehler and I share everything I know about making awesome software through my guides, screencasts, talks and courses.
Follow me on Twitter to find out what I'm currently working on.