首页 > 编程语言 > 详细

spingmvc的外置properties文件读取(java循环利用properties内容)

时间:2018-01-29 17:07:45      阅读:212      评论:0      收藏:0      [点我收藏+]

既然已经有了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);
  }

}

 

spingmvc的外置properties文件读取(java循环利用properties内容)

原文:https://www.cnblogs.com/taobr/p/8378084.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!