springboot 手动注册bean实例

@Autowired
ApplicationContext applicationContext;
private void registerSingletonBean(String beanName, Object singletonObject) {
    ConfigurableApplicationContext configurableApplicationContext = (ConfigurableApplicationContext) applicationContext;
    DefaultListableBeanFactory defaultListableBeanFactory = (DefaultListableBeanFactory) configurableApplicationContext.getAutowireCapableBeanFactory();
    defaultListableBeanFactory.registerSingleton(beanName, singletonObject);
}

posted on 2022-04-11 22:38  路过君  阅读(17)  评论(0编辑  收藏  举报

导航