I have been working with Spring for a few years now and I can consider myself with advanced Spring knowledge on the basics, rest, data, etc. But I haven’t touched on some of the other many projects that they have. In doing interviews for a Senior Software Engineer at my current company, I faced some doubts when some candidates replied to our questions. Also, we are planning a major upgrade from 2.7.x to 3.2.x so I wanted to know more about it. It was then that I found the book Pro Spring 6 in the O’Reilly library and decided to read it.

This post of Learning is from a technical book, so it may be a bit different than the other posts of the collection Learnings from books, as when I read technical books I focus more on the parts that I looking to learn and for my current situation.

Learnings from the book Pro Spring 6

The book is really good and brings some overview and also some advanced concepts on how Spring works under the hood and also brings overview and examples about some of the projects. Even if you have been using Spring for a while you may benefit from reading it, like I did.

The book has a lot of learnings, but to not be too long a post, I will share my 4 most important learnings from the book.

Spring has two proxy implementations

I was already aware of how Spring Proxy worked and their goal of intercepting method invocations and adding additional behaviors, like caching (@Cache) and transactions (@Transactional) but I have never gone deeper to check the implementations of the proxy. Basically, Spring has two proxy implementations: JDK dynamic proxies and CGLIB proxies. One of the basic differences is that JDK proxy can generate proxies only of interfaces, not classes whereas CGLIB proxy can proxy both classes and interfaces.

The main difference is cited in the book: “With the JDK proxy, all decisions about how to handle a particular method invocation are handled at runtime each time the method is invoked. When you use CGLIB, CGLIB dynamically generates the bytecode for a new class on-the-fly for each proxy, reusing already generated classes wherever possible. The resulting proxy type in this case will be a subclass of the target object class.”

Easily converting with Custom Converter

One nice thing that I learned is that we can perform conversions between custom types by implementing the Converter<S, T> interface.

Spring Native image can make the application startup faster

I have heard of GraalVM before but never in detail, but one chapter of the book brought really good information about Spring Native images.

Due to the ahead-of-time (AOT) compilation of the GraalVM native-image compiler, Spring behaves differently, as mentioned in the book

“In a typical Spring application, a lot of reflection is required to inject beans into other beans. The Spring IoC container identifies @Configuration classes and bean definitions and creates a dependency tree to decide the order in which the beans are created, so that they can be injected. All this work is done when the application starts, at runtime. In a Spring Native executable, Spring behaves differently. Configuration classes are no longer identified and parsed and bean definitions are not created at runtime; all this work is done at build time. The bean definitions are processed and converted into source code that is analyzed by the GraalVM compiler, so that the ones that are not reached (used) can be dropped. The generated code is seriously verbose, because without the power of Spring IoC, all that is left is very explicit code, injecting the right beans in the right places through classic Java code—direct assignment and explicit instantiation of the bean type. This obviously increases the build time, but that is not really a problem.”

Reactive Programming is something nice to try

In recent years there has been a lot of talk about reactive programming because, in theory, it makes the application more flexible, loosely coupled, and scalable, but I never understood it very well, but the book brings a well-explained chapter about how things work.

It is a complex subject, so better check the book or other resources, but my biggest takeaway is that both the client and server have to be reactive and all the functionalities in the flow must be as well, even the calls to the database have to be reactive.


These are my 4 most important learnings from the book Pro Spring 6: An In-Depth Guide to the Spring Framework written by Iuliana Cosmina, Rob Harrop, Chris Schaefer, Clarence Ho.

Happy coding!


Liked this post? Check out other posts part of the series Learnings from books where my goal is to share what I learned from the book that I read. It is a mixture of review and summary with a bit of my opinion and point of view