0

I have 20 beans in my application-context,I want to load a particular bean after all the beans are loaded. Is there a way for this?

skaffman
  • 398,947
  • 96
  • 818
  • 769
Chandan
  • 11
  • 2
  • 2
    What's your use-case? This is an odd requirement, perhaps it could be addressed in a more standard way. – skaffman Feb 08 '12 at 11:50

2 Answers2

1

You can use depends-on to force bean initialization order.

For example if bean1 depends on bean2 and bean3, you can put:

<bean id="bean1" class="YourBean" depends-on="bean2,bean3">

in your spring context.

soulcheck
  • 36,297
  • 6
  • 91
  • 90
0

As @skaffman said, this is a very strange requirement. Depending on your needs there are better solutions:

  • If you just need to start a process when Spring context is initialized, don't use a @PostConstruct annotated method (or an InitializingBean). ApplicationListener is probably what you need.

  • If you are worried because you need some beans injected in a @PostConstruct annotated method don't bother: Spring is usually smart enough for resolving such dependencies. If it isn't in your case, maybe you have an overcomplicated bean design.

  • If this isn't enough, you can follow @soulcheck instructions. This answer can probably help you in order to get cleaner configuration files.

If this don't help you, please give us some more information on what are you trying to achieve.

Community
  • 1
  • 1
sinuhepop
  • 20,010
  • 17
  • 72
  • 107