@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); }