I have two spring profiles that are independent from each other, like below:
<beans profile="prof1">
<security:authentication-manager id="authenticationManager" erase-credentials="true">
<security:authentication-provider ref="1" />
<security:authentication-provider ref="2" />
<security:authentication-provider ref="3" />
</security:authentication-manager>
</beans>
<beans profile="prof2" >
<security:authentication-manager id="authenticationManager" erase-credentials="true">
<security:authentication-provider ref="0" />
<security:authentication-provider ref="1" />
<security:authentication-provider ref="2" />
<security:authentication-provider ref="3" />
</security:authentication-manager>
</beans>
For instance, I can enable profile in the following way:
|prof1|prof2|
|true |true |
|true |false|
|false|true |
|false|false|
When the last option is specified spring complain that authentication-manager is missed.
In order to fix this I looked for something like "optional reference to spring bean".
Namely the idea was to extract manager from the profile like below:
<security:authentication-manager id="authenticationManager" erase-credentials="true">
<security:authentication-provider ref="0-optional-reference" />
<security:authentication-provider ref="1" />
<security:authentication-provider ref="2" />
<security:authentication-provider ref="3" />
</security:authentication-manager>
Then make bean with name "0" as optional bean. I've found the following post Optional Spring bean references but it looks like any options does not work for me because I cannot replace "ref" attribute with "value" because of spring xsd.
It would be good to know any options how can I specify optional bean for authentication-provider spring tag.