【发布时间】:2014-08-05 09:08:10
【问题描述】:
我正在尝试配置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、metrics framework 3.1.0-SNAPSHOT(我需要 jersey 2 支持)和 metrics-spring 3.0.1 中运行。我也尝试了自编译的metrics-spring 3.1.0-SNAPSHOT,但没有解决我的问题。
[编辑]
找到了这个issue,它解释了 ElementParser 不支持 SpEL。
【问题讨论】:
-
解析命名空间中的属性必须由命名空间实现,spring 不会。您可以尝试使用
#{...}而不是使用${...},这是一个可能有效的 SpEL 表达式。 -
我尝试使用 #{metrics.reporter.type} 但它不起作用。
-
这行不通,因为它会尝试在一个名为 metrics 的对象上执行 get moethd。使用 SpEL 表达式会出现什么异常。
-
BeanDefinitionParsingException 和以前一样。我认为也许metrics-spring在设置属性之前进行bean定义验证然后我遇到了这个问题。
-
请问您到底得到了什么异常!它是相同的还是嵌套的异常是不同的。正如我之前所说,对占位符的支持必须由命名空间的提供者构建到命名空间中。
标签: java spring metrics jersey-2.0