1

I have the following configuration in my spring context:

<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="prof1" >
     <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>

There is question which <beans> elements will be parsed take into account: that prof1 and prof2 profiles are activated.

It looks like it always choose this one <beans profile="prof1" >, but not sure why it does not choose another one <beans profile="!prof1" >. Can I relay that it always will choose <beans> without exclamation mark?

4

2 回答 2

2

Profile的Javadoc指出

如果给定配置文件以 NOT 运算符 (!) 为前缀,则在配置文件未激活时将注册带注释的组件

spring-beans XSD对 XML bean 定义的声明相同,但更难阅读。)

据我了解,只有prof1被视为带有profile="!prof1"的 beans 元素。您还激活prof2与此 bean 定义无关。

于 2016-03-22T09:08:56.443 回答
1

如果您的活动个人资料是 prof1 和 prof2,则以下内容将处于活动状态

<beans profile="prof1" >
 <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>

于 2016-03-22T08:42:52.793 回答