繁体   English   中英

通过.properties文件配置metrics-spring

[英]metrics-spring configuration via .properties file

我正在尝试metrics-spring via configuration file配置metrics-spring via configuration file

在我的spring.xml中,我添加了

<bean id="propertyPlaceholderConfigurer"
      class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="locations">
        <list>
            <value>
                classpath:metrics.properties
            </value>
        </list>
    </property>
    <property name="systemPropertiesModeName"
              value="SYSTEM_PROPERTIES_MODE_OVERRIDE"/>
    <property name="searchSystemEnvironment" value="true"/>
</bean>

充满像

metrics.reporter.type=console

然后在spring配置中设置它,通过$ {metrics.reporter.type}访问该属性

<metrics:reporter metric-registry="metrics" type="${metrics.reporter.type}" period="1m"/>

在Web应用程序启动期间,由于上述unresolved variable ,spring抛出BeanDefinitionParsingException

配置问题:找不到报告程序类型'$ {metrics.reporter.type}'的ReporterElementParser

我正在通过mongo主机和端口使用此配置方法(通过属性文件),它的工作原理就像一个魅力。

我在Tomcat7,Spring 4.0.5.RELEASE,指标框架3.1.0-SNAPSHOT(我需要球衣2支持)和metrics-spring 3.0.1中运行。 我还尝试使用自编译指标-Spring 3.1.0-SNAPSHOT,但不能解决我的问题。

[编辑]

发现了此问题 ,这说明ElementParser不支持SpEL。

恐怕在type属性中不能使用属性占位符。 Spring不会解析属性占位符或SpEL,直到metrics-spring之后的阶段读取type属性并解析report元素(允许将占位符和bean引用用于所有其他属性时,此元素是必需的)。

一种可能的解决方案是配置您可能要使用的所有报告者,并在enabled属性中使用占位符:

<metrics:reporter metric-registry="metrics" type="console" period="1m"
                  enabled="${metrics.reporter.console.enabled}" />

<metrics:reporter metric-registry="metrics" type="slf4j" period="1m"
                  enabled="${metrics.reporter.slf4j.enabled}" />

和属性文件:

metrics.reporter.console.enabled=true
metrics.reporter.slf4j.enabled=false

我希望这很有意义,我已经度过了很长的一周!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM