分阶段加载spring上下文 [英] Load spring context in phases
问题描述
这是人们会问的那些奇怪的问题之一-为什么?
This is one of those strange questions where people would ask - why?
因此,我将从为何要这样做的原因开始,然后讨论这个问题.我想对如何加载spring上下文有更多的控制.例如,我不想同时加载域和web-api.这将使资源在它们的依赖关系就绪之前可用. 在继续进行此过程之前,可能还需要检查某些事物的状态.可以这么说,模块/上下文之间将存在顺序.也许不仅是在启动,而且还在关机中.
So I will start with why I would like to do this and then go into the issue. I would like to have more control over how the spring context is loaded. For example, I do not want to load the domain and web-api at the same time. That would make the resources available before their dependencies are ready. There might also be that I need to check the state of something before I can continue this process. So to say, there will be sequential order between modules/contexts. Maybe not just booting but also in shutdown.
所以问题是我找不到有关如何加载域上下文的任何信息,然后在完成后我将检查状态并最后加载api上下文.我想从Java代码中完成所有这些操作,因为我需要控制启动流程.我有一些使用SpringServlet加载Web上下文的基础知识.我尚未找到任何信息,是是否有可能加载上下文,等待并加载引用第一个上下文的另一个上下文.
So the issue is that I can't find any information on how to load the domain-context, then when that is finished I would check the state and lastly load the api-context. I would like to do all of this from java-code as I need to control the flow of the start up. I have basics working with SpringServlet loading the web-context. What I have not found any information on is if it is possible to load a context, wait and load another context that refers to the first one.
很高兴知道我没有使用JavaEE或容器.我只在servlet和spring中使用嵌入式Jetty.那么有什么方法可以做到吗?
It might be good to know that I am not using JavaEE nor a container. I am only using embeddded Jetty with servlet and spring. So is there a way this can be done?
推荐答案
考虑延迟加载的bean和延迟代理. 因此,仅在首次使用时才创建Bean ...
Consider lazy loaded beans and Lazy Proxy. So the bean will be created only on first usage ...
这篇关于分阶段加载spring上下文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!