首页 > 代码库 > spring bean的生命周期

spring bean的生命周期

package com.huawei.entity;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

public class Test implements BeanNameAware,BeanFactoryAware,InitializingBean,ApplicationContextAware ,DisposableBean{

public Test(){
System.out.println("test初始化");
}

public void setBeanName(String arg0) {
System.out.println("Test.setBeanName()");
}

public void setBeanFactory(BeanFactory arg0) throws BeansException {
System.out.println("Test.setBeanFactory()");
}

public void afterPropertiesSet() throws Exception {
System.out.println("Test.afterPropertiesSet()");
}

public void setApplicationContext(ApplicationContext arg0) throws BeansException {
System.out.println("Test.setApplicationContext()");
}

public void destroy() throws Exception {
System.out.println("Test.destroy()");
}
public void init(){
System.out.println("Test.init()");
}
}

spring bean的生命周期