import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;
import org.springframework.web.context.ContextLoaderListener;
import org.springframework.web.context.WebApplicationContext;
WebApplicationContext ac = ContextLoaderListener.getCurrentWebApplicationContext(); //ApplicationContext ac = SpringContext.getApplicationContext(); String[] strings=ac.getBeanDefinitionNames(); System.out.println(strings.length); AutowireCapableBeanFactory beanFactory = ac.getAutowireCapableBeanFactory(); beanFactory.autowireBean(a); String name = a.getClass().getName(); beanFactory.initializeBean(a, name); strings=ac.getBeanDefinitionNames(); System.out.println(strings.length); for (String string : strings) { System.out.println(string); }
时间: 2024-10-11 00:39:52