AnnotationConfigApplicationContext and parent context

后端 未结 5 696
暖寄归人
暖寄归人 2021-01-03 05:29

I\'m facing an issue trying to define a context hierarchy using AnnotationConfigApplicationContext.

The problem is when defining a module context insid

5条回答
  •  不知归路
    2021-01-03 06:08

    I also run into a similar problem and after some research I found the following approach using a constructor from AnnotationConfigApplicationContext that allows to set the a hierarchy between contexts

    DefaultListableBeanFactory lbf = new DefaultListableBeanFactory(parentContext);
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(lbf);
    context.register(annotatedClass1.class, annotatedClass2.class);
    context.refresh();
    

提交回复
热议问题