Из-за архитектуры подключаемого модуля я пытаюсь добавить программный код bean в мой webapp. У меня есть Spring bean, созданный с помощью аннотации @Component
, и я реализую интерфейс ApplicationContextAware
.
Моя функция переопределения выглядит следующим образом:
@Override
public void setApplicationContext(ApplicationContext applicationContext)
throws BeansException {
// this fails
this.applicationContext = (GenericWebApplicationContext) applicationContext;
}
В принципе, я не могу понять, как добавить bean к объекту applicationContext, заданному для setApplicationContext. Может ли кто-нибудь сказать мне, как я это делаю неправильно?
Хорошо, это то, с чем я столкнулся, как решение:
@Override
public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry bdr)
throws BeansException {
BeanDefinition definition = new RootBeanDefinition(
<My Class>.class);
bdr.registerBeanDefinition("<my id>", definition);
}