首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

Spring-Init-Method步骤的实现

2013-01-01 
Spring---Init-Method方法的实现学习笔记,转自:http://abin888.blog.sohu.com/59985097.html???1.在spring

Spring---Init-Method方法的实现

学习笔记,转自:http://abin888.blog.sohu.com/59985097.html

?

?

?

1.在spring中,先执行属性配置,在执行afterPropertySet()方法,最后init()方法

2.配置文件改为

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">

<beans>
?<bean id="test" class="test.Test"?init-method="init">
??<property name="name">
???<value>chenhaibin</value>
??</property>
?</bean>
</beans>

3.在Test中增加一个init方法

package test;

import org.springframework.beans.factory.InitializingBean;

public class Test implements InitializingBean
{

?private String name;
?
?public String getName()
?{
??return name;
?}

?public void setName(String name)
?{
??System.out.println("-----------setName-------");
??this.name = name;
?}

?public void afterPropertiesSet() throws Exception
?{
??System.out.println("--------afterPropertyiesSet---------");

?}
?
?public void init() throws Exception
?{
??System.out.println("--------init---------");

?}

}
4.测试结果是

2007-08-16 15:39:00,549 DEBUG [org.springframework.beans.CachedIntrospectionResults] - <Found property 'class' of type [java.lang.Class]>
2007-08-16 15:39:00,549 DEBUG [org.springframework.beans.CachedIntrospectionResults] - <Found property 'name' of type [java.lang.String]>
2007-08-16 15:39:00,549 DEBUG [org.springframework.beans.CachedIntrospectionResults] - <Class [test.Test] is cache-safe>
2007-08-16 15:39:00,549 DEBUG [org.springframework.beans.factory.xml.XmlBeanFactory] - <Eagerly caching bean with name 'test' to allow for resolving potential circular references>
2007-08-16 15:39:00,565 DEBUG [org.springframework.beans.BeanWrapperImpl] - <About to invoke write method [public void test.Test.setName(java.lang.String)] on object of class [test.Test]>
-----------setName-------
2007-08-16 15:39:00,565 DEBUG [org.springframework.beans.BeanWrapperImpl] - <Invoked write method [public void test.Test.setName(java.lang.String)] with value of type [java.lang.String]>
2007-08-16 15:39:00,565 DEBUG [org.springframework.beans.factory.xml.XmlBeanFactory] - <Invoking BeanPostProcessors before initialization of bean 'test'>
2007-08-16 15:39:00,565 DEBUG [org.springframework.beans.factory.xml.XmlBeanFactory] - <Invoking afterPropertiesSet() on bean with name 'test'>
--------afterPropertyiesSet---------
2007-08-16 15:39:00,565 DEBUG [org.springframework.beans.factory.xml.XmlBeanFactory] - <Invoking custom init method 'init' on bean with name 'test'>
--------init---------
2007-08-16 15:39:00,565 DEBUG [org.springframework.beans.factory.xml.XmlBeanFactory] - <Invoking BeanPostProcessors after initialization of bean 'test'>

热点排行