如何让Spring打印出哪些弹簧轮廓是活动的? [英] How to get Spring to print out what spring profiles are active?

查看:133
本文介绍了如何让Spring打印出哪些弹簧轮廓是活动的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用spring 3.1配置文件,并希望Spring在启动时打印出哪些配置文件处于活动状态。例如,日志文件中输出的前几行。

I am using spring 3.1 profiles and want would like Spring to print out on startup what profiles are active. For example are the first few lines of the output in the log file.

02:59:43,451 INFO  [ContextLoader] Root WebApplicationContext: initialization started
02:59:43,544 INFO  [XmlWebApplicationContext] Refreshing Root WebApplicationContext: startup date [Sun Dec 30 02:59:43 EST 2012]; root of context hierarchy
02:59:43,610 INFO  [XmlBeanDefinitionReader] Loading XML bean definitions from class path resource [spring.xml]
02:59:43,835 INFO  [XmlBeanDefinitionReader] Loading XML bean definitions from class path resource [spring-security.xml]
02:59:43,971 INFO  [SpringSecurityCoreVersion] You are running with Spring Security Core 3.1.3.RELEASE
02:59:43,971 INFO  [SecurityNamespaceHandler] Spring Security 'config' module version is 3.1.3.RELEASE

我想从春天看到的是打印出来的东西正在使用的弹簧版本以及当前活动的配置文件。

What I want to see from spring is something that prints out the version of spring in use along with which profiles are currently active.

如何弹出打印出版本以及哪些配置文件处于活动状态?

How can I get spring to printout it's version and what profiles are active?

推荐答案

实施 EnvironmentAware 界面

例如

class MyEnvironmentAware implements EnvironmentAware{
    private static Environment env = null;

    @Override
    public void setEnvironment(Environment environment) {
            env = environment;
            //log the stuff you want here
     }
}

将此类标记为Spring bean

Mark this class as Spring bean

只需注入 环境 合二为一急切加载豆子并打印出你需要的细节

just inject Environment in one of your eagerly loading bean and print the detail you need from it

喜欢

@Autowired
Environment env;

在您急切加载的bean中,打印出来

in your eagerly loading bean, and print it

这篇关于如何让Spring打印出哪些弹簧轮廓是活动的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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