Spring injection using setter and constructor, use inti and destroy method in bean
Whenever a single bean object is created in a this config file, all of the beans declared in this file will be created.
Using setter-------------------
<bean class="" name="" init-method="" destroy-method="">
<properties name="">
<value>
//give value here
</value>
</properties>
</bean>
or
<bean class="" name="" init-method="" destroy-method="">
<properties name="" value="">
</properties>
</bean>
or
<bean class="" name="" p:nameOfVariable="" init-method="" destroy-method=""/> //this is using p schema
Using constructor
Using setter-------------------
<bean class="" name="" init-method="" destroy-method="">
<constructor-args name="">
<value>
//give value here
</value>
</constructor-args>
</bean>
or
<bean class="" name="" init-method="" destroy-method="">
<constructor-args name="" value="">
</constructor-args>
</bean>
or
<bean class="" name="" c:nameOfVariable="" init-method="" destroy-method=""/> //this is using c schema
Using annotation
@PostConstruct
@PreDestroy
This two annotation is used before init and destroy method
It is enabled by using both way in xml file.
<context:annotation-config/>
or
<bean class="org.springframework.context.annotation.CommonAnnotationBeanPostProcessor/>
Comments
Post a Comment