@PostConstruct public void registerBeanDefinition() { DefaultListableBeanFactory beanFactory = (DefaultListableBeanFactory) ((AnnotationConfigEmbeddedWebApplicationContext) applicationContext).getBeanFactory(); if (error.isEmpty()) return; Set<Map.Entry<String, String>> entries = error.entrySet(); Iterator<Map.Entry<String, String>> iterator = entries.iterator(); while (iterator.hasNext()) { Map.Entry<String, String> next = iterator.next(); RootBeanDefinition beanDefinition = new RootBeanDefinition(ErrorCode.class); ConstructorArgumentValues constructor = new ConstructorArgumentValues(); constructor.addIndexedArgumentValue(0, next.getKey()); constructor.addIndexedArgumentValue(1, next.getValue()); beanDefinition.setConstructorArgumentValues(constructor); beanFactory.registerBeanDefinition(next.getKey(), beanDefinition); }
spring 容器启动完成以后,在想注入bean,该怎么注入
最新推荐文章于 2022-04-12 17:26:27 发布