
Originally Posted by
bonnyr
Thanks for the quick reply.
Could you please elaborate on your comment below:
You can apply IOC to all beans.. not only the singleton beans. But the life cycle management of non singleton beans is more complicated in Spring because the container doesn`t do any life cycle management after a non singleton bean is created.
I still cannot get my mind around how an IoC implementation can take
care of doing its magic on objects which are not those heavyweight,
configurable objects, and how an application would go about using
the container to do this.
If a bean is created, a method could be called on that bean (initialize). And because the container registers all singleton beans ( I don`t know if it registers non singleton beans), the container could signal the beans as soon as the container shutsdown.
Would there be an example you'd share?
Mailer is a bean in my system that needs some life cycle management. You can see the 'init-method' and 'destroy-method' part.
Code:
<bean id="mailer"
class="mail2mail.server.sender.Mailer"
init-method="startup"
destroy-method="shutdown">
<!-- poolSize -->
<constructor-arg index="0">
<value>5</value>
</constructor-arg>
<!-- de prioriteit van de verstuur thread..
1 = minimaal, 10 = maximaal, 5 = default
-->
<constructor-arg index="1">
<value>3</value>
</constructor-arg>
<!-- maxBatchSize -->
<constructor-arg index="2">
<value>50</value>
</constructor-arg>
<!-- smtpConnectionSettings -->
<constructor-arg index="3">
<ref bean="smtpConnectionSettings"/>
</constructor-arg>
</bean>