This project demonstrates the complete Spring Bean Lifecycle using Spring Core and XML-based configuration.
It shows how Spring creates, initializes, manages, and destroys beans inside the IoC Container.
- Spring IoC Container
- Bean Creation
- Dependency Injection (Setter Injection)
- XML Bean Configuration
- Bean References (
ref) - Bean Properties (
property) - Custom Initialization Method
- Custom Destruction Method
- Bean Lifecycle
- Maven Project Structure
- Java
- Spring Framework (Core)
- Maven
- XML Configuration
- Eclipse IDE
src
├── main
│ ├── java
│ │ └── example
│ │ └── message_converters_withlifecycle
│ │ ├── App.java
│ │ ├── MessageConverter.java
│ │ ├── IMessageConverter.java
│ │ ├── HtmlMessageConverter.java
│ │ └── PDFMessageConverter.java
│ │
│ └── resources
│ └── com
│ └── configuration
│ └── application-context.xml
The project configures beans using application-context.xml.
<bean id="msgConverter"
class="example.message_converters_withlifecycle.MessageConverter"
init-method="init"
destroy-method="destroy">
<property name="converter" ref="html"/>
<property name="message" value="Hello guys"/>
</bean>Container Starts
│
▼
Bean Instantiation
│
▼
Dependency Injection
│
▼
init() Method
│
▼
Bean Ready to Use
│
▼
Application Running
│
▼
Context Closed
│
▼
destroy() Method
Message Converter object created
Init method called
MessageConverter [converter=example.message_converters_withlifecycle.HtmlMessageConverter@..., message=Hello guys]
Destruction method called
- Clone the repository
git clone <repository-url>
-
Open the project in Eclipse or IntelliJ IDEA.
-
Update Maven dependencies.
-
Run:
App.java
- How Spring creates beans
- Bean lifecycle inside the IoC container
- XML-based bean configuration
- Setter Dependency Injection
- Bean references using
ref - Custom initialization and destruction callbacks
- Proper closing of
ApplicationContext
- BeanPostProcessor
- InitializingBean
- DisposableBean
- @PostConstruct
- @PreDestroy
- Annotation-based configuration
- Java Config
- Prototype Bean Lifecycle
- Bean Scopes
Prakhar Panchal
If you found this project helpful, consider giving it a ⭐.