KZKY memo

自分用メモ.

init-methodが呼ばれる順番

defaultはparent -> child
depen-onを使うと順番を逆にできる.
  • bean def file
<bean id="parent" scope="singleton" class="edu.kzk.spring_sample.init_method.Parent" init-method="init_parent" depends-on="child">
	<property name="var" value="parent"/>
</bean>


<bean id="child" scope="singleton" parent="parent" class="edu.kzk.spring_sample.init_method.Child" init-method="init_child">
	<property name="var" value="child"/>
</bean>
  • output
...
[22:26:44 INFO  Parent] - ### Constructor ###
[22:26:44 INFO  Child] - ### Constructor ###
[22:26:44 DEBUG AbstractAutowireCapableBeanFactory] - Eagerly caching bean 'child' to allow for resolving potential circular references
[22:26:44 INFO  Parent] - ## setVar ##
[22:26:44 DEBUG AbstractAutowireCapableBeanFactory] - Invoking init method  'init_child' on bean with name 'child'
[22:26:44 INFO  Child] - ## init_child ##
[22:26:44 DEBUG AbstractAutowireCapableBeanFactory] - Finished creating instance of bean 'child'
[22:26:44 DEBUG DefaultSingletonBeanRegistry] - Creating shared instance of singleton bean 'parent'
[22:26:44 DEBUG AbstractAutowireCapableBeanFactory] - Creating instance of bean 'parent'
[22:26:44 INFO  Parent] - ### Constructor ###
[22:26:44 DEBUG AbstractAutowireCapableBeanFactory] - Eagerly caching bean 'parent' to allow for resolving potential circular references
[22:26:44 INFO  Parent] - ## setVar ##
[22:26:44 DEBUG AbstractAutowireCapableBeanFactory] - Invoking init method  'init_parent' on bean with name 'parent'
[22:26:44 INFO  Parent] - ## init_parent ##
...