
How Spring Container Works and Why Proxies Surprise You
Follow a bean from definition to proxy to destruction, and learn why scopes, proxies and transactions behave the way they do inside the container.
Tag
18 posts

Follow a bean from definition to proxy to destruction, and learn why scopes, proxies and transactions behave the way they do inside the container.

Dependency injection means a class receives its collaborators instead of building them. See what that buys in tests and wiring, and what Spring adds.

Follow one HTTP request through filters, the DispatcherServlet, handler mapping, argument resolution, the controller and the response writer.

Resolve the Spring error about several matching beans with @Primary, @Qualifier or by injecting all of them, and learn which one fits.

Understand the two causes of BeanCurrentlyInCreationException, a true dependency cycle and an early reference that later got wrapped in a proxy.

Read a BeanCreationException trace to its root cause and fix the usual culprits: constructors that throw, bad schemas and absent services.

Compare constructor, setter and field injection in Spring on immutability, testing, circular dependencies and required versus optional collaborators.

Write a REST controller in Spring MVC with request mappings, status codes, validation and a test, using a small orders resource as the example.

Fix NoSuchBeanDefinitionException by telling apart a missing type, a missing name and a bean hidden by scanning, profiles or a child context.

Return correct HTTP status codes from Spring MVC with ResponseStatus, ResponseEntity, ResponseStatusException and handlers, and know which fits.

Read the nested messages of UnsatisfiedDependencyException to find the real problem behind a failed constructor, setter or field injection.

Fix TransactionRequiredException when saving or running an update query by placing a transaction around the call and checking that the proxy applies.