1.xml文件
<bean id="aaa" class="com.dingwang.Test.Aaa" init-method="init">
<constructor-arg name="name" value="ddd"></constructor-arg>
</bean>
2.java文件
public Aaa(String name) {
LOGGER.warn("--------------------Aaa-----------------Aaa");
this.setName(name);
}
public void init() {
LOGGER.warn("--------------------Aaa-----------------init");
}
/*
* (non-Javadoc)
* @see
* org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
*/
@Override
public void afterPropertiesSet() throws Exception {
LOGGER.warn("--------------------Aaa-----------------afterPropertiesSet");
}
3.执行日志
10:44:54.116 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating instance of bean 'aaa'
10:44:54.157 [main] WARN com.dingwang.Test.Aaa - --------------------Aaa-----------------Aaa
10:44:54.159 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Eagerly caching bean 'aaa' to allow for resolving potential circular references
10:44:54.171 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Invoking afterPropertiesSet() on bean with name 'aaa'
10:44:54.172 [main] WARN com.dingwang.Test.Aaa - --------------------Aaa-----------------afterPropertiesSet
10:44:54.172 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Invoking init method 'init' on bean with name 'aaa'
10:44:54.172 [main] WARN com.dingwang.Test.Aaa - --------------------Aaa-----------------init
10:44:54.173 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Finished creating instance of bean 'aaa'
4.结论
执行顺序:构造函数>afterPropertiesSet>init-method