@Autowired
DefaultListableBeanFactory defaultListableBeanFactory = new DefaultListableBeanFactory();
AbstractBeanDefinition definition = BeanDefinitionBuilder.genericBeanDefinition().getBeanDefinition();
definition.setBeanClass(ClueOrigin.class);
defaultListableBeanFactory.registerBeanDefinition("a",definition);
System.out.println(defaultListableBeanFactory.getBean("a"));
读取
AnnotationConfigApplicationContext configApplicationContext = new AnnotationConfigApplicationContext();
AnnotatedBeanDefinitionReader reader = new AnnotatedBeanDefinitionReader(configApplicationContext);
reader.register(ClueOrigin.class);
configApplicationContext.refresh();
System.out.println(configApplicationContext.getBean("clueOrigin"));