简体   繁体   English

通过.properties文件配置metrics-spring

[英]metrics-spring configuration via .properties file

I'm trying to configure metrics-spring via configuration file 我正在尝试metrics-spring via configuration file配置metrics-spring via configuration file

In my spring.xml I've added 在我的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>

filled with something like 充满像

metrics.reporter.type=console

and then I'm setting it in the spring config accessing that property via ${metrics.reporter.type} 然后在spring配置中设置它,通过$ {metrics.reporter.type}访问该属性

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

During the startup of the web application, spring throws a BeanDefinitionParsingException due to the unresolved variable above 在Web应用程序启动期间,由于上述unresolved variable ,spring抛出BeanDefinitionParsingException

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

I'm using this configuration method (via properties file) for mongo host and port and it works like a charm. 我正在通过mongo主机和端口使用此配置方法(通过属性文件),它的工作原理就像一个魅力。

I'm running in Tomcat7, Spring 4.0.5.RELEASE, metrics framework 3.1.0-SNAPSHOT (I need jersey 2 support) and metrics-spring 3.0.1. 我在Tomcat7,Spring 4.0.5.RELEASE,指标框架3.1.0-SNAPSHOT(我需要球衣2支持)和metrics-spring 3.0.1中运行。 I also tried with a self-compiled metrics-spring 3.1.0-SNAPSHOT but doesn't solve my problem. 我还尝试使用自编译指标-Spring 3.1.0-SNAPSHOT,但不能解决我的问题。

[EDIT] [编辑]

Found this issue which explain that SpEL is not supported by the ElementParser. 发现了此问题 ,这说明ElementParser不支持SpEL。

I'm afraid it isn't possible to use a property placeholder in the type attribute. 恐怕在type属性中不能使用属性占位符。 Spring does not resolve property placeholders or SpEL until the phase after metrics-spring reads the type attribute and parses the reporter element (which is necessary to allow placeholders and bean references to be used in all the other attributes). Spring不会解析属性占位符或SpEL,直到metrics-spring之后的阶段读取type属性并解析report元素(允许将占位符和bean引用用于所有其他属性时,此元素是必需的)。

A possible solution would be to configure all the reporters you might want to use, and use a placeholder in the enabled attribute: 一种可能的解决方案是配置您可能要使用的所有报告者,并在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}" />

And the properties file: 和属性文件:

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

I hope this makes sense, I've had a very long week! 我希望这很有意义,我已经度过了很长的一周!

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

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