简体   繁体   English

在Spring中列出已解析的属性

[英]Listing the resolved properties in Spring

I have multiple property file sources in my spring xml files, they have different order values and some are optional. 我的spring xml文件中有多个属性文件源,它们有不同的顺序值,有些是可选的。

  • application.properties - in the classpath, holds the default (fallback) properties (lowest priority) application.properties - 在类路径中,保存默认(回退)属性(最低优先级)
  • [HOSTNAME].properties - in the classpath, holds properties specific for that hostname (higher priority) [HOSTNAME] .properties - 在类路径中,包含特定于该主机名的属性(更高优先级)
  • Property file loaded by value in jndi - location specified in via jndi, highest priority. 在jndi中按值加载的属性文件 - 在via jndi中指定的位置,最高优先级。

In other words, I can override the default properties set in application.properties with properties in .properties and override those values in turn by a property file whose location is looked up by jndi. 换句话说,我可以使用.properties中的属性覆盖application.properties中设置的默认属性,并依次通过jndi查找其位置的属性文件覆盖这些值。

What I would like to have however is some way for spring to give my a list of the resolved values of all the properties. 然而,我希望有一些方法让spring给出我所有属性的已解析值列表。 Anyone know how I can do this? 谁知道我怎么做到这一点?

It's easy for me to get the value of a particular property but what I actually need is a list of all the resolved properties. 我很容易获得特定属性的值,但实际需要的是所有已解析属性的列表。

I have two suggestions: 我有两个建议:

  1. You can override the class PropertyPlaceholderConfigurer with method processProperties to populate all the resolved properties. 您可以使用方法processProperties覆盖类PropertyPlaceholderConfigurer以填充所有已解析的属性。 An example is listed here . 这里列出一个例子。
  2. Since PropertyPlaceholderConfigurer implements Spring's Ordered interface, you can have multiple property place holders; 由于PropertyPlaceholderConfigurer实现了Spring的Ordered接口,因此您可以拥有多个属性占位符; then, assign them the order in the order that should be in your application. 然后, order应用程序中应该的order为他们分配order Finally, having been already extended the class, you will have access to all resolved properties in the order that should be loaded. 最后,在已经扩展了类之后,您将可以按应加载的顺序访问所有已解析的属性。

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

相关问题 未解析文件中定义的 Spring 属性 - Spring Properties Defined in File not Resolved 在Spring上下文XML中无法解析属性 - Properties aren't resolved in Spring context XML Spring PropertyConfigurer-找到文件,但属性未解析 - Spring PropertyConfigurer - File Found but properties not getting resolved 使用Maven在Spring XML中无法解析系统属性 - System properties can't be resolved in Spring XML using Maven 在将Spring解析的属性注入bean之前,如何对其进行修改 - How to modify properties resolved by Spring before their injection into beans Spring解析的属性文件位置需要解析那些属性 - Spring resolved property file location needs to resolve those properties Spring Boot - 无法从application.properties解析xml中的属性 - Spring Boot - property could not be resolved in xml from application.properties 属性值未使用 spring 引导从 application.properties 解析 - property value not resolved from application.properties using spring boot 使用 Java 和 Spring 引导和我的 application-dev.properties 的 @Value 注释没有得到解决? - Using Java and Spring Boot and my @Value annotation for my application-dev.properties is not being resolved? Spring @valid 注解无法解析 - Spring @valid annotation cannot be resolved
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM