0
我是相互獨立的,如下面兩個彈簧輪廓:標籤認證經理
<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>
例如,我可以通過以下方式啓用配置:
|prof1|prof2|
|true |true |
|true |false|
|false|true |
|false|false|
當最後一個選項被指定時,彈簧會抱怨身份驗證管理器錯過了。
爲了解決這個問題,我尋找類似「可選參考春豆」。
即當時的想法是從配置文件中提取經理象下面這樣:
<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>
然後,讓名稱爲「0」 bean作爲可選豆。我發現了以下帖子Optional Spring bean references,但它看起來像任何選項不適合我,因爲我不能用「值」替換「ref」屬性,因爲spring xsd。
這將是很好的知道任何選項我怎麼能指定可選的豆認證供應商春天標籤。
感謝奧利弗的提示答案。我只是在考慮兩個配置文件都處於活動狀態時的情況。哪一個會被認爲是有效的。它看起來像聲明,將是有效的。 –
fashuser
當兩個配置文件都處於活動狀態時,2 AuthenticationManagers可用於注入並具有相同的「權重」,這可能會導致Spring抱怨發現給定bean類型的多個實現。要解決這個問題,你可以將其中一個標記爲「primary」:' ',這樣在注入查找時優先。 –
我已經試過這個bean標記,但它看起來像是不允許通過Spring xsd來設置這樣的屬性。是否可以指定任何其他屬性? – fashuser