How do you implement property placeholders in Spring?
Inject externalised configuration into Spring beans with @Value placeholders, defaults, Environment and typed @ConfigurationProperties records.
2,882 posts about Java: questions with answers, tutorials and articles, newest first.
Inject externalised configuration into Spring beans with @Value placeholders, defaults, Environment and typed @ConfigurationProperties records.
@Conditional makes Spring register a bean or configuration only when a custom Condition returns true. See examples, Boot variants and common pitfalls.
@Profile registers a bean or configuration class only when a given profile is active, so one code base can switch between dev, test and production wiring.
Spring's default bean scope is singleton, one shared instance per container. See how to declare it, keep it thread-safe and mix scopes safely.
Use @Scope prototype to get a new bean instance per request, understand lifecycle limits, and inject fresh instances into singletons with ObjectProvider.
BeanPostProcessor lets you run custom logic on every Spring bean before and after initialization. See the lifecycle, a working example, ordering rules and pitfalls.
Implement BeanPostProcessor to intercept bean creation in Spring, wrap beans in proxies, and avoid early-initialisation pitfalls with static @Bean methods.
Use @ComponentScan on a configuration class or context:component-scan in XML to register stereotype-annotated classes as beans, and how Boot handles it.
@Autowired makes Spring inject a matching bean into a constructor, setter or field. See how resolution works, how to pick between beans and how to fix common errors.
Spring injects dependencies through its IoC container using constructors, setters or fields. See which style to prefer and how to resolve multiple matching beans.
The @Bean annotation turns a method's return value into a Spring-managed bean. See how it differs from @Component and how to use scope, lifecycle and conditions.
Define Spring beans in plain Java with @Configuration classes and @Bean methods. Covers injection, scopes, profiles, composition and lite mode.
@Configuration lets Spring define beans in type-safe Java instead of XML. Learn @Bean, scopes, @Import, proxyBeanMethods and how to bootstrap it.
Implement the ErrorController interface, map /error, and return a view or JSON based on the status code. Includes Spring Boot 3 specifics and simpler options.
ErrorController marks the Spring Boot controller behind /error. Implement it to replace the default Whitelabel page and JSON error response.
Add custom HTML error pages and RFC 9457 JSON error responses in Spring Boot, and hide internals in production.
RedirectAttributes carries data across a redirect in Spring MVC, using URL parameters or one-time flash attributes, and prevents duplicate form posts.
Redirect with the redirect: prefix, RedirectView, ResponseEntity or sendRedirect, pick the correct status code, and avoid open redirect vulnerabilities.
RedirectView is the Spring MVC view that sends an HTTP redirect, used for the Post/Redirect/Get pattern, custom status codes and passing data safely.
Use the redirect: prefix, RedirectView or ResponseEntity to send redirects in Spring MVC, pass data with RedirectAttributes, and apply Post/Redirect/Get safely.