Spring 上下文中的进度条?
我想创建一个带有进度条的窗口,它显示 Spring 对象实例化的当前状态。 来自 Spring.Net 的文档 似乎 IObjectPostProcessors
是在实例化对象时启动和跟踪的正确点。 然而,为了获得“实例化类的百分比”,我需要询问 Spring 工厂的 ObjectDefinitionCount
来获取配置对象的数量。 然而,在上下文创建完成之前这不起作用(也这个问题问题似乎是相关的)。
如果无法使用Spring获取启动状态,那么如何在应用程序启动过程中向用户显示信息?
I would like to create a window with a progressbar which shows the current status of Spring's object instantiation. From Spring.Net's documentation it seems that IObjectPostProcessors
is the right point to start and track whenever an Object has been instanciated. However in order to get "Percentage of instantiated classes" I need to ask ObjectDefinitionCount
of spring's factory to get the number of configured object. However this does not work until the contextcreation has been finished (also this problem problem seems to be related).
If it's not possible to use Spring to get the start-up status, how do you display information during application start up to the user?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我可以为您提供一个解决方法,尽管它并不完美,但可能是一个不错的估计。
当然,这并不准确,但大多数时候它应该提供一个很好的估计。
I can provide you with a workaround, although it's not perfect it should probably be a good estimate.
Of course, this is not accurate, but it should provide a good estimate most of the times.
Spring 分两步读取配置 - 首先从配置中读取所有对象定义,然后处理这些定义,必要时实例化单例。
您应该通过实现 IObjectFactoryPostProcessor 来获得您想要的结果。 ObjectFactoryPostProcessor 是首先实例化的对象。 此时对象定义的数量已经可用。 使用 IObjectPostProcessor 可以为您提供有关正在实例化的每个对象的信息。
如果您在加载配置时已经获取了对象定义的数量,我想这是可能的,但 Spring 会一次性读取配置。 您需要使用不同的技术来获取对象的总数。
哈,
埃里希
Spring reads in the configuration in 2 steps - first all object definitions are read from the config and second those definitions are processed, instantiating singletons if necessary.
You should get what you want by implementing an IObjectFactoryPostProcessor. ObjectFactoryPostProcessors are the first objects that get instantiated before anything else. At this time the number of object definitions is already available. Using an IObjectPostProcessor gives you the information about each object being instantiated.
If you are after getting the number of object definitions already at the time the configuration is loaded, I guess it is possible, but Spring reads the configuration in a single pass. You'd need to obtain the total number of objects using a different technique.
hth,
Erich