设置“活动配置文件"通过 AbstractAnnotationConfigDispatcherServletInitializer 类? [英] Setting "Active Profile" through Class AbstractAnnotationConfigDispatcherServletInitializer?
问题描述
在扩展 AbstractAnnotationConfigDispatcherServletInitializer 类时,您将如何设置活动配置文件"属性?
How would you set the "active profile" property when extending the class AbstractAnnotationConfigDispatcherServletInitializer ?
推荐答案
根据您要设置的上下文配置文件,一种方法是覆盖
Depending which contexts' profiles you want to set, one way to do it is to override the
AbstractAnnotationConfigDispatcherServletInitializer#createRootApplicationContext()
和
AbstractAnnotationConfigDispatcherServletInitializer#createServletApplicationContext()
在那里设置活动配置文件.例如
to set the active profiles in there. For example
@Override
protected WebApplicationContext createRootApplicationContext() {
WebApplicationContext context = (WebApplicationContext)super.createRootApplicationContext();
((ConfigurableEnvironment)context.getEnvironment()).setActiveProfiles("profiles");
return context;
}
注意 super
调用.您需要这样,以便超级实现从您的 @Configuration
类(或您指定的任何上下文)实际创建 WebApplicationContext
.
Note the super
call. You'll want this so that the super implementation actually creates the WebApplicationContext
from your @Configuration
classes (or any context you specified).
这篇关于设置“活动配置文件"通过 AbstractAnnotationConfigDispatcherServletInitializer 类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!