Spring 配置文件:应解析哪个 <beans> 元素?
Spring profiles: Which <beans> element should be parsed?
我的 spring 上下文中有以下配置:
<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>
存在将解析哪些 <beans>
个元素的问题:
prof1 和 prof2 配置文件已激活。
看起来总是选择这个<beans profile="prof1" >
,但不知道为什么不选择另一个<beans profile="!prof1" >
。我可以转述它总是会选择 <beans>
而不带感叹号吗?
如果您的活动配置文件是 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>
If a given profile is prefixed with the NOT operator (!), the annotated component will be registered if the profile is not active
(spring-beans XSD 与 XML bean 定义相同,但更难阅读。)
据我了解,对于带有 profile="!prof1" 的 beans 元素,只查看 prof1。您还激活 prof2 与此 bean 定义无关。
我的 spring 上下文中有以下配置:
<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>
存在将解析哪些 <beans>
个元素的问题:
prof1 和 prof2 配置文件已激活。
看起来总是选择这个<beans profile="prof1" >
,但不知道为什么不选择另一个<beans profile="!prof1" >
。我可以转述它总是会选择 <beans>
而不带感叹号吗?
如果您的活动配置文件是 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>
If a given profile is prefixed with the NOT operator (!), the annotated component will be registered if the profile is not active
(spring-beans XSD 与 XML bean 定义相同,但更难阅读。)
据我了解,对于带有 profile="!prof1" 的 beans 元素,只查看 prof1。您还激活 prof2 与此 bean 定义无关。