Filter
Exclude
Time range
-
Near
Did you know? ☕🌱 `@PostConstruct` runs automatically after a Bean is created, while `@PreDestroy` runs before the Bean is removed from the Spring container ⚡ Perfect for initialization and cleanup tasks 👀
1
3
51
What happens to a Spring bean from creation to termination? 👉 Bean Definition → Metadata registered when @ ComponentScan finds @ Component, @ Service, @ Repository classes. Or when @ Bean method parsed in @ Configuration classes. BeanDefinition contains: class name, scope (singleton/prototype), dependencies, factory method, init/destroy method names. Constructor Invocation → Spring uses reflection to instantiate via constructor. For @ Component class with no explicit constructor, default no-arg constructor called. For @ Bean methods, method called to create instance. If multiple constructors, @ Autowired marks which to use. Dependency Injection → Spring resolves constructor parameters via @ Autowired, injects matching beans. For setter injection (@ Autowired on setter), setter called after construction. For field injection (@ Autowired on field), reflection used to set field directly. Autowire by type, then qualifier, then name. BeanNameAware Interface → If bean implements BeanNameAware, setBeanName(String name) called with bean's registration name. Allows bean to know its own name in container. BeanFactoryAware Interface → If bean implements BeanFactoryAware, setBeanFactory(BeanFactory factory) called. Bean can query factory for other beans if needed. BeanClassLoaderAware Interface → If bean implements BeanClassLoaderAware, setBeanClassLoader(ClassLoader classLoader) called. Provides classloader context. InitializingBean Interface → If bean implements InitializingBean, afterPropertiesSet() called after all properties set and aware callbacks done. Allows custom initialization logic like opening connections. @ PostConstruct Method → If method annotated with @ PostConstruct, it's called after construction and dependency injection complete. Runs before bean is available to others. Can only have one, no parameters except @ Inject optional. BeanPostProcessor.postProcessAfterInitialization() → Custom BeanPostProcessor implementations can wrap or modify bean. Runs after all initialization. Used for proxying (AOP), validation, dynamic bean enhancement. Bean Ready → Bean now available in ApplicationContext. Can be injected into other beans. Singleton beans exist for lifetime of context. Prototype beans used and discarded per request. @ PreDestroy Method → When context shuts down, @ PreDestroy method called on beans. Allows cleanup: close database connections, stop timers, release resources. Runs in reverse order of creation. DisposableBean Interface → If bean implements DisposableBean, destroy() method called on shutdown. Alternative to @ PreDestroy. Both called if present; order depends on implementation."
1
15
77
25,319
8 Dec 2025
Spring PostConstruct and PreDestroy Annotations: buff.ly/LwskuQU

1
16
2,486
¿Conoces el ciclo de vida que tiene un Bean de Spring para que puedas usarlo? 👀 Te lo explico 1. Instanciación → Spring crea el objeto de tu clase (new MiServicio()). 2. Inyección de dependencias → se resuelven las referencias con @ Autowired, constructor o setters. 3. PostProcess → los BeanPostProcessor pueden modificar el bean antes de que lo uses (ej: proxys para @ Transactional u otras anotaciones). 4. Inicialización → si tu clase implementa InitializingBean o anotas con @ PostConstruct, aquí corre ese código 5. Bean listo → ahora sí lo puede usar tu app. 6. Destrucción → al apagar el contexto, Spring llama a @ PreDestroy o a destroy() si implementas DisposableBean. Si alguna vez te preguntaste en qué momento Spring activa la lógica detrás de anotaciones como @ Transactional o @ Async ahora ya sabes que todo ocurre en el paso 3. 💡 Entonces esto es entender mucho de lo que está detrás de Spring y el conocimiento por lo general nos ayuda a tomar mejores decisiones.
10
173
The most common crash I find in UE5 around this is usually something that is using a timer or ticker when the world or engine exits. It’s too easy to register a delegate and forget to unbind it in the correct function, Unregister, predestroy or destroy? Also copy paste mistakes
1
2
299
🌱 Spring Bean Lifecycle: 1️⃣ Constructor → Bean created 2️⃣ Dependencies injected 3️⃣ @PostConstruct → init logic 4️⃣ Bean ready 5️⃣ @PreDestroy → cleanup Also: InitializingBean.afterPropertiesSet() DisposableBean.destroy() Know these = ace Spring interviews 💡 #SpringBoot #Java
1
4
61
Final Step: Destruction When the application shuts down, Spring manages the bean's destruction. It calls shutdown hooks in order for resource cleanup: - @PreDestroy methods - destroy() (from DisposableBean) - A custom destroy-method
1
3
66
Example: Using @ PostConstruct, @ PreDestroy, and ApplicationRunner in Spring Boot Java ✅
1
10
72
3,041
Spring Boot Lifecycle Hooks: @ PostConstruct, @ PreDestroy, ApplicationRunner ✅
12
101
7,091
18 Jun 2025
Spring Bean Lifecycle Behind the Scenes of Every Bean: The Spring Bean Lifecycle defines how a bean is created, initialized, and destroyed within the Spring container. Understanding it helps in customizing bean behavior using hooks like @PostConstruct, @PreDestroy, and lifecycle interfaces.
1
9
56
3,183
16 Jun 2025
Another Common Springboot Interview : Q: How do you implement graceful shutdown in Spring Boot? Ans : Spring Boot (from v2.3 ) supports graceful shutdown using the config: server.shutdown=graceful spring.lifecycle.timeout-per-shutdown-phase=30s This ensures Spring waits for active requests to complete before shutting down the app. To clean up resources (Kafka consumers, DB connections, thread pools), use: @ PreDestroy on beans Implement DisposableBean or SmartLifecycle Override close() for custom beans You can say something like this to sound experienced: "We observed that without proper shutdown, some Kafka offsets weren't committed, leading to duplicate processing. After enabling graceful shutdown and handling bean lifecycle correctly, the issue was resolved."
1
14
130
6,753
Day 25 of leveling up in Java Backend ➤ Had an interesting task in internship today, understood @PostConstruct and @PreDestroy in Spring Boot ➤ DSA : ⇒ Find combination of string(subset) #java #dsa #buildinpublic
1
15
142
🚀 Day 181 of #Coding 🚀 DSA Progress: ✅ Prim's Algorithm ✅ Disjoint Set [Union by Rank] ✅ Disjoint Set [Union by Size] SpringBoot Progress: ✅ @PostConstruct & @PreDestroy ✅ @Bean Annotation #Java #SpringBoot #DSA #Graphs #100daysofCoding #DSA #leetcode #GFG
5
48
23 Nov 2024
Spring PostConstruct and PreDestroy Annotations: buff.ly/2W0fMNv (from the archive)

3
12
2,064
31 Aug 2024
- implementing aware Interfaces to modify behaviour of Bean LifeCycle (method execution before or after bean has been created) - using @PostConstruct and @PreDestroy annotations to execute methods before or after bean has been created #100DaysOfCode #Java #spring #springBoot
1
1
1
59
Bean Life Cycle : Application Start IOC Container Construct Bean Inject Dependency into a Bean PostConstruct Use the Bean PreDestroy
1
4
333
Bean Life Cycle : Application Start IOC Container Construct Bean Inject Dependency into a Bean PostConstruct Use the Bean PreDestroy
1
143
コードはあれで直るけど、元々hitEffect()ってメソッド名の通りメソッドの目的は被弾した時の点滅演出なのよね たまたまライフ1の敵だからジャンパー線引いて(そのせいでバグったけど)本来は消滅時追加処理(preDestroy())を基底クラス側で準備して呼び出すべきなのよね
1
3
114