设置“活动配置文件"通过 AbstractAnnotationConfigDispatcherServletInitializer 类? [英] Setting "Active Profile" through Class AbstractAnnotationConfigDispatcherServletInitializer?

查看:25
本文介绍了设置“活动配置文件"通过 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆