Advanced wiring in Spring Part-2
In the last article we have seen that how we can configure beans based on certain environments.This is quite useful features spring have provided.Sometimes we need more granular control over the bean autowiring in spring, such as we need certain beans that needs to be autowired or injected on some complex condition (which is something more than certain environment). for e.g. What if we need certain bean needs to be injected if some other bean have specific property value. or inject an bean only if some other class is found on class-path. Here Spring will help you to make such a configuration using @Conditional annotation. Suppose we want the bean OperationUser to be created if the property " department= Operations " is set in your properties file. @Bean @Conditional(OpsDepartmentCondition.class) public OperationsUser operationsUser(){ OpeartionsUser opsUser = new OperationsUser(); return opsUser; } We will take a look at how OpsDepartmentCondition will