引用参考:
--Spring提供的InitializingBean接口初始化bean
[url]https://www.cnblogs.com/study-everyday/p/6257127.html[/url]
[url]https://blog.csdn.net/u010595903/article/details/42712731[/url]
--Spring bean 通过实现 InitializingBean ,DisposableBean 接口
[url]https://blog.csdn.net/chenwiehuang/article/details/52594074[/url]
[url]https://blog.csdn.net/topwqp/article/details/8681573[/url]
//
1、提供一个类,实现InitializingBean接口
2、Spring的bean配置文件
3、测试类
--Spring提供的InitializingBean接口初始化bean
[url]https://www.cnblogs.com/study-everyday/p/6257127.html[/url]
[url]https://blog.csdn.net/u010595903/article/details/42712731[/url]
--Spring bean 通过实现 InitializingBean ,DisposableBean 接口
[url]https://blog.csdn.net/chenwiehuang/article/details/52594074[/url]
[url]https://blog.csdn.net/topwqp/article/details/8681573[/url]
//
1、提供一个类,实现InitializingBean接口
import org.springframework.beans.factory.InitializingBean;
import mbp.gateway.web.msgcontent.content.BaseContent;
public class StudentBean implements InitializingBean{
/**
* 重写InitializingBean提供的afterPropertiesSet方法
*/
@Override
public void afterPropertiesSet() throws Exception {
System.out.println("初始化StudentBean=");
}
/**
* 自定义初始化方法
*/
public void initBean(){
System.out.println("测试init-method 初始化bean StudentBean");
}
}
2、Spring的bean配置文件
<bean name="studentBean " class="com.demo.bean.StudentBean " init-method="initBean">
<property name="targetMaps">
<map>
<entry key="Grade1">
<map>
<entry key="c1,c2,c3,c4">
<ref bean="commonClassContent" />
</entry>
</map>
</entry>
</map>
</property>
</bean>
<bean name="commonClassContent" class="com.demo.bean.CommonClassContent" />
3、测试类
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
public class Demo {
public static void main(String[] args) {
ApplicationContext context=new FileSystemXmlApplicationContext("/src/main/resources/com/demo/baseContent.xml");
System.out.println("context="+context);
}
}