I have a FileSystemXmlApplicationContext
and I would like the beans defined in the XML to take as a constructor argument a bean which is not declared in Spring
As I had trouble solving this with an AnnotationConfigApplicationContext, I found the following alternative:
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
beanFactory.registerSingleton("customBean", new CustomBean());
context = new AnnotationConfigApplicationContext(beanFactory);
context.register(ContextConfiguration.class);
context.refresh();