Junior — Middle
How is the destruction of beans in the Spring container carried out upon application shutdown?
sobes.tech AI
Answer from AI
In Spring, the destruction of beans upon application shutdown occurs through the invocation of lifecycle methods that implement interfaces or are annotated with specific annotations:
- If a bean implements the
DisposableBeaninterface, thedestroy()method is called. - If a method is specified in the configuration using the
destroyMethodattribute (for example,@Bean(destroyMethod =