How do you implement custom scopes for beans in Spring?
Create a custom Spring bean scope by implementing the Scope interface, registering it with CustomScopeConfigurer, and using scoped proxies for singleton injection.
2,887 posts about Java: questions with answers, tutorials and articles, newest first.
Create a custom Spring bean scope by implementing the Scope interface, registering it with CustomScopeConfigurer, and using scoped proxies for singleton injection.
The @Bean annotation marks a method that creates a Spring bean. See how to define, wire, name and scope beans in Java config and choose between @Bean and scanning.
Register Spring beans only when a property, profile, class or other bean is present, using @Conditional, custom conditions and the Spring Boot ConditionalOn annotations.
@Profile makes Spring register beans only when a named profile is active. See expressions, activation methods and Spring Boot profile files and groups.
Use a @Configuration class with @Bean methods to register beans in Spring. See dependency wiring, scopes, profiles and how it compares to component scanning.
@Configuration marks a Spring class as a source of @Bean definitions. See Java config examples, full versus lite mode and proxyBeanMethods.
Constructor injection hands required beans to a class through its constructor. See working examples, ambiguity fixes and how it compares to setter and field injection.
Where should @Autowired go in Spring? Compare constructor, setter and field injection with runnable examples and learn how Spring resolves ambiguous or missing beans.
Use WebClient to make non-blocking HTTP calls in Spring WebFlux. Learn configuration, GET and POST requests, error handling, retries and parallel calls.
subscribeOn sets the thread of the source and subscription; publishOn switches the thread for downstream operators. See examples, schedulers and common mistakes.
Reactor runs on the subscribing thread until you use subscribeOn or publishOn. See how each works, which scheduler to pick and how to handle blocking calls.
The Schedulers class controls which threads run your reactive pipeline. Learn the built-in schedulers, subscribeOn versus publishOn, and how to wrap blocking code.
The difference between map and flatMap on Mono and Flux in Project Reactor, with examples, ordering and concurrency rules, and the concatMap alternatives.
Mono emits zero or one item and Flux emits zero to many. Learn how they work, how to combine them and how they are used in Spring WebFlux, with working examples.
How to create reactive streams in Java using java.util.concurrent.Flow and Project Reactor, with backpressure, errors and StepVerifier tests.
ReactiveMongoTemplate is Spring Data MongoDB's non-blocking API for custom queries, atomic updates, aggregations and transactions using Mono and Flux.
Add the reactive MongoDB starter, map a @Document entity and extend ReactiveMongoRepository to get non-blocking CRUD and derived queries in Spring WebFlux.
JDBC blocks a thread per query; reactive access with R2DBC does not. Compare models, transactions and tooling, and learn when virtual threads are enough.
A reactive Spring Data repository extends ReactiveCrudRepository and returns Mono and Flux, giving non-blocking database access for Spring WebFlux with MongoDB or R2DBC.
In WebFlux, @RestController works like in MVC but returns Mono and Flux. See a reactive controller, SSE streaming and when to prefer MVC.