简体   繁体   English

在任何其他Bean之前先弹簧加载一个Bean

[英]Spring Load A Bean Before Any Other Bean

I have a requirement that I want to initialize a bean before any other bean in my application context. 我有一个要求,我要在应用程序上下文中的任何其他bean之前先初始化一个bean。 One way to do is to use "depends-on" on every other bean but its too verbose as I have many beans in my application-context. 一种方法是在每个其他bean上使用“ depends-on”,但是它太冗长,因为我在应用程序上下文中有很多bean。

Is there any other way to do this. 还有其他方法可以做到这一点。 I have read abt implementing ServletContext for this but I dont think this will work as this has nothing to do with Spring. 我已经读过实现ServletContext的方法,但是我认为这不会起作用,因为这与Spring无关。

Please let me know your thoughts on it. 请让我知道您对此的想法。

Thanks, Raunak 谢谢,劳纳克

Make sure that your bean comes first in your context.xml and it will be instantiated first. 确保您的bean首先出现在context.xml中,并且将首先实例化它。 You can make a simple test to verify. 您可以进行简单的测试来验证。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM