[英]How to specify the default profile that beans will be registered under in Spring?
鉴于:
<beans ... namespace decelerations>
<bean id="foo" class="com.example.foo" />
<beans profile="abc">
<bean id="bar" class="com.exmaple.bar" />
</beans>
</bean>
foo注册的个人资料的名称是什么? 有没有办法在另一个配置文件定义中覆盖foo? 如果未明确指定配置文件,是否在spring中有默认配置文件的名称。
spring中的默认配置文件是“default”,请参阅: https : //jira.springsource.org/browse/SPR-8203
您可以通过执行以下操作更改web.xml中的默认配置文件:
<context-param>
<param-name>spring.profiles.default</param-name>
<param-value>production</param-value>
</context-param>
命令行:
-Dspring.profiles.default=production
环境变量:
export spring_profiles_default=production
如果设置了活动配置文件,则它将覆盖默认配置文件。
Foo
只是在没有配置文件的情况下注册,无论您在该环境中使用的配置文件如何,它都将始终实例化。 Spring
只允许在具有相同id
的XML
文件中创建多个bean,如果它们位于不同的<beans>
集中,那么如果它不在一个带有a <beans>
的<beans>
标记内,我认为不可能覆盖Foo
bean。轮廓。
如果没有定义配置文件,Spring将使用名为default
的配置文件。 但是,一bean
是不是里面<beans>
标签与配置文件将不被该配置文件下注册。 它只表示如果你有类似下面的XML
并且没有提供配置文件,那么将加载具有默认配置文件的bean以及没有配置文件的bean。
<beans ... namespace decelerations>
<bean id="foo" class="com.example.foo" />
<beans profile="default">
<bean id="bar" class="com.exmaple.bar" />
</beans>
</bean>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.