Spring
Posts
-
Digging into Spring's Source 5: How @Autowired Picks the Bean to Inject — Dependency Resolution
Which bean Spring puts into an @Autowired field or constructor, how it finds that bean, and how it chooses when there are several — followed through the real source. Candidate lookup, the precedence of @Primary, @Qualifier and name matching, List and Map injection, the constructor selection rules, and what happens when nothing is found, each checked by running an example.
-
Digging into Spring's Source 6: Lifecycle Callbacks and PostProcessors — Where You Can Step into the Container
When exactly, and in what order, are BeanFactoryPostProcessor, BeanPostProcessor and its sub-interfaces, the Aware interfaces, @PostConstruct, InitializingBean, init-method, @PreDestroy, DisposableBean, destroy-method, SmartInitializingSingleton and SmartLifecycle called? Checked against the real source and real program output, with a look at why there are so many different hooks.
-
Digging into Spring's Source 7: The Twelve Steps of refresh() — the Order in Which the Container Starts
Behind the single line new AnnotationConfigApplicationContext(...) runs refresh(). This post opens its twelve steps one by one, and checks in the real source and with runnable examples what ApplicationContext adds on top of BeanFactory, why there are two branches (GenericApplicationContext and AbstractRefreshableApplicationContext), and what happens when startup fails or when close() is called.
-
Digging into Spring's Source 8: How @Configuration and @ComponentScan Become Blueprints
How a configuration class (@Configuration), its @Bean methods, and the @Component classes found by @ComponentScan turn into bean blueprints (BeanDefinition), followed step by step for someone new to Spring. How ConfigurationClassPostProcessor reads blueprints to add more blueprints, how component scanning reads class files without loading them, and why a @Configuration class is wrapped with CGLIB so that calling a @Bean method twice still gives you the same object — all checked against the real source and runnable examples.
-
Digging into Spring's Source 9: @Conditional, @Profile and @Import — Choosing Beans by Condition
How @Conditional and @Profile, which register a bean only when a condition holds, and @Import, which pulls in other configuration, are evaluated inside the container — when and how — explained for someone new to Spring. Why a condition is evaluated three times, the three kinds of @Import, what DeferredImportSelector "defers" and why, the ImportStack that catches circular imports, and why every @EnableXxx is just @Import in disguise, all checked against the real source and small runnable examples.
-
Digging into Spring's Source 10: How an AOP Proxy Gets Built — the JDK Way and the CGLIB Way
How a single ProxyFactory.getProxy() call decides between a JDK dynamic proxy and a CGLIB proxy, how each one is built, and how a call on the proxy travels through the interceptor chain to the target object — all checked against the real source. Also why calling your own method from inside the class skips the advice, and the trap with final methods, shown with runnable examples.
-
Digging into Spring's Source 11: How @Aspect Gets Discovered and How the Advice Chain Runs
What the single line @EnableAspectJAutoProxy registers in the container, how an @Aspect class is turned into advisors, how the container decides which beans to wrap in a proxy, and in what order @Around, @Before, @After, @AfterReturning and @AfterThrowing run when a proxied method is called — all checked against the real source and real example output.
-
Digging into Spring's Source 12: Events, Environment, Resource — Three Abstractions Around the Container
The three things ApplicationContext adds on top of BeanFactory — events (publishing and listening), Environment (configuration values and profiles) and Resource (reading files and the class path) — explained for someone new to Spring, with where each one hooks into refresh(). The journey of one publishEvent call, why a system property beats a properties file, and where the "classpath:" prefix turns into a class, all checked against the real source and run as examples.
-
Digging into Spring's Source 13: ResolvableType and MergedAnnotations — How Spring Reads Types and Annotations
How Spring finds the String in List<String> (ResolvableType), how it reads annotations stacked on annotations and @AliasFor as one merged view (MergedAnnotations), and how it reads a .class file without loading the class (MetadataReader) — checked against the real source with runnable examples, for someone new to Spring.
-
Digging into Spring's Source 14: Type Conversion and BeanWrapper — From a String to an Object's Property
How the string "8080" from a configuration file ends up in a bean's int field, followed through the source. Why Spring has both PropertyEditor and ConversionService and which one it asks first, how BeanWrapper walks a path like "address.city", and where the container plugs these two in — explained for someone seeing Spring for the first time.
-
Digging into Spring's Source 15: SpEL — How an Expression Is Parsed and Evaluated
How a string like "#{T(java.lang.Math).max(a, 3) + 1}" becomes tokens, then a tree, then a value, followed through the source. How operator precedence is expressed as the call order of parser methods, why there are two evaluation contexts (StandardEvaluationContext and SimpleEvaluationContext), the compiler mode that turns an expression into bytecode, and the path a @Value("#{…}") takes inside the container — explained for someone seeing Spring for the first time.
-
Digging into Spring's Source 16: Utilities and AOT — the Shared Toolbox and Computing Ahead of Time
Why spring-core carries its own utilities (Assert, ClassUtils, ReflectionUtils, three special maps, OrderComparator) that every module uses, where they appear and where they bite, and how Spring 6's AOT "computes ahead" by turning a container into Java source and RuntimeHints at build time — all checked against the real source and running examples.
-
Digging into Spring's Source 17: @Transactional — Who Opens a Transaction and Who Closes It
Put @Transactional on a method and somebody opens a transaction, rolls it back on an exception and commits it otherwise — this post follows who that somebody is, in the real source. The three interfaces PlatformTransactionManager, TransactionDefinition and TransactionStatus, the beans that @EnableTransactionManagement registers, the order in which TransactionInterceptor wraps a call, where propagation branches, why the connection is bound to a ThreadLocal, and traps such as "checked exceptions do not roll back" and "the outer method gets an UnexpectedRollbackException when the inner one fails", all checked with examples.
-
Digging into Spring's Source 18: JdbcTemplate — the Template-Callback Pattern and Exception Translation
Plain JDBC repeats the same chores on every query — get a connection, build a Statement, handle the exception, close everything. This post follows, in the source, how JdbcTemplate gathers those chores into one place and leaves your code only a callback; how it shares a connection with @Transactional; and how a SQLException turns into a Spring exception such as DuplicateKeyException, including which translator is the default in 7.x. Written for someone seeing Spring for the first time.
-
Digging into Spring's Source 19: ORM and R2DBC Integration — JPA Support and Reactive Transactions
How JPA's EntityManagerFactory becomes a bean, why the EntityManager you get from @PersistenceContext is safe to share between threads, how JdbcTemplate ends up on the same connection under JpaTransactionManager, and where a @Repository's exceptions get translated — all checked in the source. Then the reactive side, where there is no thread to hang a transaction on, and R2DBC transactions ride in the Reactor Context instead.
-
Digging into Spring's Source 20: The spring-web Foundation — HttpMessageConverter, WebApplicationContext, Filters
A first-timer's read of spring-web, the module that both Spring MVC and WebFlux stand on. The interfaces that model an HTTP message as an object, HttpMessageConverter turning a body into a Java object and the rule for picking one, the spot where the Spring container starts inside a Servlet container (ContextLoaderListener), and how a filter that runs only once per request is built — all checked against the source and with runnable examples.
-
Digging into Spring's Source 21: DispatcherServlet — How One Request Becomes a Response
We follow a single HTTP request through Spring MVC by reading the source of DispatcherServlet. Written for people new to Spring, it covers how the servlet sets up its own context and strategy objects at startup, and the order in which doDispatch finds a handler, calls it, and weaves in interceptors and exception handling.
-
Digging into Spring's Source 22: Handler Mappings and Adapters — How @RequestMapping Methods Are Found and Called
When and where a method annotated with @GetMapping gets registered, which of several candidate methods wins for a request, who fills in the chosen method's arguments, and who turns its return value into a response — followed through the source of RequestMappingHandlerMapping and RequestMappingHandlerAdapter. Examples show the two different "ambiguous mapping" errors and exactly where a custom argument resolver slots in.
-
Digging into Spring's Source 23: Exception Handling, Interceptors, Views — Before, After, and the End of a Request
How HandlerInterceptors that run around a controller method are lined up and why only the ones whose preHandle passed get afterCompletion, in what order an exception thrown by a controller travels through the HandlerExceptionResolvers until it reaches an @ExceptionHandler method, and how a single view name goes through ViewResolver and View to end in a forward to a JSP — all checked against the real source and the output of small examples.
-
Digging into Spring's Source 24: WebFlux — DispatcherHandler, Functional Endpoints, and WebClient
Follow the path a request takes through Spring WebFlux, in the source. We look at how WebFilter and WebExceptionHandler are woven together under HttpHandler, at DispatcherHandler as the reactive counterpart of DispatcherServlet, at how annotated controllers and functional endpoints share one road, and at the filter chain inside WebClient.
-
Digging into Spring's Source 25: WebSocket and Messaging — How a STOMP Message Flows
Follows one STOMP message from the browser through an @MessageMapping method and out to every subscriber, in the source. The Message, channel and handler abstractions of spring-messaging, the handshake in spring-websocket, and the three channels and simple broker that connect them — explained for someone who has never seen WebSocket before.
-
Digging into Spring's Source 26: spring-test — SpringExtension, TestContext, MockMvc
Put one annotation on a test class and a container starts, beans get injected, and transactions roll back. We check in the real source how SpringExtension connects JUnit to Spring, how the context cache and its key start a context only once for the same configuration, how test transactions work, and how MockMvc runs the real DispatcherServlet without a server.
-
Digging into Spring's Source 27: Caching, Scheduling, Validation, Resilience — Features Built on Top of the Container
@Cacheable, @Scheduled, @Async, @Validated and @Retryable look like separate features, but inside they repeat one pattern. For readers new to Spring, this post checks in the source what each switch annotation registers, which post-processor wraps the bean, and which interceptor intercepts the call, and then wraps up the whole series.
-
Digging into Spring's Source 1: How I Read It with AI, and the Map
The first post of the Spring source-reading series, starting with what Spring is, how it works and what it is for — shown first through the smallest possible example, pictures and a three-minute exercise. It then explains how an 840,000-line codebase is split into small units and read with the help of AI, how to get exactly the same source, and the order the reading will follow.
-
Digging into Spring's Source 2: The Big Map — Modules and Packages
A map for anyone opening the Spring Framework repository for the first time. What each of the 22 modules does, how they depend on one another, what lives inside spring-core, spring-beans, spring-context and spring-aop, and the big picture of container start-up — all checked against the real build files and source.
-
Digging into Spring's Source 3: The BeanFactory Hierarchy and BeanDefinition
Before Spring builds an object it prepares a blueprint for it (BeanDefinition), and it hands objects out through a front desk (BeanFactory) that is split into several small interfaces. This post follows both through real source excerpts and diagrams, written for someone new to Spring.
-
Digging into Spring's Source 4: How a Bean Gets Created — the Creation Flow and the Three-Level Cache
What happens inside Spring when getBean() is called once, followed step by step for someone new to Spring. The cache lookup, the three creation steps (instantiate, inject, initialise), and how three maps untangle a circular reference where A needs B and B needs A — all checked against the real source.