zoukankan      html  css  js  c++  java
  • spingmvc的外置properties文件读取(java循环利用properties内容)

    既然已经有了applicationContext.xml的properties路径,java不必再properties路径。

    applicationContext.xml

    改前:

    <!-- properties -->

    <context:property-placeholder location="file:/sb/env.properties" />

    改后:

    <!-- properties -->
    <bean class="jp.co.softbank.faqapi.common.conf.AppConfig">
      <property name="locations">
        <list>
          <value>file:/sb/env.properties</value>
        </list>
      </property>
    </bean>

    java文件:

    import java.util.Properties;

    import org.springframework.beans.BeansException;
    import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
    import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
    import org.springframework.stereotype.Component;

    /**
    * コンフィギュレーション.
    */
    @Component
    public class AppConfig extends PropertyPlaceholderConfigurer {

      private Properties properties;

      @Override
      protected void processProperties(ConfigurableListableBeanFactory beanFactoryToProcess, Properties properties)throws BeansException {
        super.processProperties(beanFactoryToProcess, properties);
        this.properties = properties;
      }

      /**
      * ENVのプロパティ取得
      * @param key キー
      * @return 値
      */
      public String getEnvProperty(String key){
        return properties.getProperty(key);
      }

    }

  • 相关阅读:
    python 基础1-变量名
    Jmeter分布式测试踩过的坑
    Jmeter接口测试踩过的坑
    搭建数据库环境
    char与char的区别
    jmeter性能测试的小小实践
    自动化测试badboy脚本开发(一)
    sql多表查询(单表查询略过)
    认识jmeter
    http与https的区别
  • 原文地址:https://www.cnblogs.com/taobr/p/8378084.html
Copyright © 2011-2022 走看看