【问题标题】:Can One property value be assigned to another property in other properties file可以将一个属性值分配给其他属性文件中的另一个属性吗
【发布时间】:2013-08-02 09:48:31
【问题描述】:

我有两个.properties 文件,其中每个文件的两个属性值相同。所以我想将一个值引用到另一个值,例如:

1.config.properties

 path= /opt/logs/bundle

2.default.properties

default =/opt/logs/bundle(与 config.properties 中的路径相同)

现在这里默认属性值与路径相同,所以我想给出如下:

default = {path}

但在这里我无法获得该路径。谁能帮帮我。谢谢

【问题讨论】:

  • Java?还是其他什么技术?请添加合适的语言/技术标签
  • 你在谈论哪种技术?
  • 我正在使用java,spring..

标签: java spring spring-mvc properties


【解决方案1】:

在我的项目中,已使用 EncryptablePropertySourcesPlaceholderConfigurer,然后已为其父“PropertiesLoaderSupport”的“资源 [] 位置”属性分配了我要加载的每个属性文件。我想这就是我没有遇到任何错误的原因。

例如:

<bean id="frameworkPropertyPlaceholderConfigurer"
    class="org.jasypt.spring31.properties.EncryptablePropertySourcesPlaceholderConfigurer">
    <constructor-arg ref="stringEncryptor" />
    <property name="ignoreUnresolvablePlaceholders" value="true" />
    <property name="locations">
        <list>
            <bean parent="frameworkConfigResourceFactoryBean">
                <property name="resourceName" value="framework-config.properties" />
            </bean>
            <bean ................> </bean>
        </list>
    </property>
</bean>

并且在 database-config.properties 中:

 database.driver.class=com.mysql.jdbc.Driver
 database.connection.url=${database.connection.url}
 database.username=root
 database.password=${database.password}

也在 filter.properties 中:

 database.connection.url=jdbc:mysql://localhost:3306/MySQLDBName?rewriteBatchedStatements=true
 database.password=root

【讨论】:

    【解决方案2】:

    java 中的Properties 类没有引用其他属性的功能。如果您曾经见过使用引用的.properties 文件,那么解释该.properties 文件的应用程序会在Properties 类的顶部添加此功能。例如。如果您找到以{ 开头并以} 结尾的值,则必须自己查找属性路径。

    另一方面,当使用某个库的特定配置文件格式(如 spring 的 bean.xml)时,该库可能在​​其格式中添加了引用。很有可能,您可以找到一个库,该库在 java 的 Properties 设施之上添加了引用,或者 Spring 已经在其庞大的“任何您需要的”包中提供了一些东西。

    【讨论】:

    • 你知道任何一个这样的库,它位于支持此类引用的属性之上。
    • 请看:stackoverflow.com/questions/872272/…,eproperties 是提到的库的名称...
    • 我想添加依赖而不是jar..你知道怎么做吗..如果是的话请告诉我
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-03
    • 2011-02-17
    相关资源
    最近更新 更多