整體流程圖
成都創(chuàng)新互聯(lián)公司不只是一家網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司;我們對營銷、技術(shù)、服務(wù)都有自己獨特見解,公司采取“創(chuàng)意+綜合+營銷”一體化的方式為您提供更專業(yè)的服務(wù)!我們經(jīng)歷的每一步也許不一定是最完美的,但每一步都有值得深思的意義。我們珍視每一份信任,關(guān)注我們的網(wǎng)站制作、成都網(wǎng)站設(shè)計質(zhì)量和服務(wù)品質(zhì),在得到用戶滿意的同時,也能得到同行業(yè)的專業(yè)認(rèn)可,能夠為行業(yè)創(chuàng)新發(fā)展助力。未來將繼續(xù)專注于技術(shù)創(chuàng)新,服務(wù)升級,滿足企業(yè)一站式全網(wǎng)整合營銷推廣需求,讓再小的品牌網(wǎng)站制作也能產(chǎn)生價值!程序示例
maven依賴
org.springframework
spring-context
4.3.12.RELEASE
junit
junit
4.12
test
配置類
@Configuration
@ComponentScan("per.ym.processor, per.ym.service")
public class LifeCycleConfig {
@Bean(initMethod = "init", destroyMethod = "destroy")
public LifeCycleBean lifeCycleBean() {
return new LifeCycleBean();
}
}
實例bean
public class LifeCycleBean implements InitializingBean, BeanNameAware, BeanFactoryAware, BeanClassLoaderAware {
public LifeCycleBean() {
System.out.println("consturctor......");
}
public void init() {
System.out.println("init......");
}
@Autowired
public void setService(PersonService service) {
System.out.println("setService......");
}
public void destroy() {
System.out.println("destroy......");
}
@Override
public void afterPropertiesSet() throws Exception {
System.out.println("afterPropertiesSet......");
}
@Override
public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
System.out.println("setBeanFactory......");
}
@Override
public void setBeanName(String name) {
System.out.println("setBeanName......");
}
@Override
public void setBeanClassLoader(ClassLoader classLoader) {
System.out.println("setBeanClassLoader......");
}
}
InstantiationAwareBeanPostProcessor
package per.ym.processor;
@Component
public class MyInstantiationBeanPostProcessor extends InstantiationAwareBeanPostProcessorAdapter {
@Override
public Object postProcessBeforeInstantiation(Class> beanClass, String beanName) throws BeansException {
if (beanName.equals("lifeCycleBean")) {
System.out.println("postProcessBeforeInstantiation......");
}
return null;
}
@Override
public boolean postProcessAfterInstantiation(Object bean, String beanName) throws BeansException {
if (beanName.equals("lifeCycleBean")) {
System.out.println("postProcessAfterInstantiation......");
}
return true;
}
@Override
public PropertyValues postProcessPropertyValues(
PropertyValues pvs, PropertyDescriptor[] pds, Object bean, String beanName) throws BeansException {
if (beanName.equals("lifeCycleBean")) {
System.out.println("postProcessPropertyValues......");
}
return pvs;
}
}
BeanPostProcessor
package per.ym.processor;
@Component
public class MyPostProcess implements BeanPostProcessor {
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
if (beanName.equals("lifeCycleBean")) {
System.out.println("postProcessBeforeInitialization......");
}
return bean;
}
@Override
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
if (beanName.equals("lifeCycleBean")) {
System.out.println("postProcessAfterInitialization......");
}
return bean;
}
}
service
package per.ym.service;
@Service
public class Service {
}
測試類
public class Test_Normal {
AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(LifeCycleConfig.class);
@Test
public void test() {
applicationContext.getBean("lifeCycleBean");
applicationContext.close();
}
}
測試結(jié)果:
postProcessBeforeInstantiation......
consturctor......
postProcessAfterInstantiation......
postProcessPropertyValues......
setService......
setBeanName......
setBeanClassLoader......
setBeanFactory......
postProcessBeforeInitialization......
afterPropertiesSet......
init......
postProcessAfterInitialization......
destroy......
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機、免備案服務(wù)器”等云主機租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。