RKJ
RKJ

Reputation: 11

Spring dependency injection controll

How do I control/restrict the instantiation of bean?

Lets say, I have 2 beans

  1. A.java
  2. B.java

Scopes of the both the bean as singleton & configured inside Spring application context

If A bean gets instantiated then B shouldn't vice-versa if B gets instantiated the A shouldn't.

Upvotes: 0

Views: 35

Answers (1)

Adrian
Adrian

Reputation: 3134

You can use @Conditional or @Profile. For first annotation you can write a class which will check if your bean exists.

Upvotes: 1

Related Questions