//获取bean工厂
DefaultListableBeanFactory beanFactory = applicationContext.getDefaultListableBeanFactory();
//移除beanDefinition,注意,这里spring会帮我们把相关依赖也移除
beanFactory.removeBeanDefinition("testService");
//自定义一个新的bean class
RootBeanDefinition bd = new RootBeanDefinition(subClass);
bd.setScope(SCOPE_SINGLETON);
//注册bean definition,之后如果相关的bean
beanFactory.registerBeanDefinition("testService", bd);
spring本身提供了相应的bean移除、bean定义和生成接口,只需要调用相关接口即可实现功能