后台properties配置独立tomcat之外配置方法

一、各环境修改tomcat目录下配置文件进行配置

通过修改catalina.sh配置(TOMCAT_HOME/bin)

进入catalina.sh找到

JAVA_OPTS='-Xms512m -Xmx512m -XX:PermSize=256M -XX:MaxNewSize=256m -XX:MaxPermSize=512m -Dfile.encoding=UTF-8'

JAVA_OPTS的值插入以下语句

在后面加上 -Dglobal.config.path=/usr/local/jconfig

红色字体根据配置文件所在的位置修改

《后台开发人员》本地通过idea启动包时,需要添加以下配置

使用idea的maven启动,需要在edit configurations -Runner中添加Environment variables:global.config.path=E:/maps-jushi/project-setting/dev;

红色字体修改为项目路径,如图

164348_bb0s_2322635.png

以上方法不行,则采用以下方法:

在parameters的command line内增加“-Dglobal.config.path=E:\gitworkplace\maps-jushi\project-setting”

clean -Pdev tomcat7:run -Dmaven.tomcat.port=8081 -Dglobal.config.path=E:\gitworkplace\maps-jushi\project-setting

195817_CRh4_2322635.png

 

二、java的文件SystemProperties写法

package com.zdnst.common.infra.utils;



import java.util.Properties;


/**
 * 读取web.properties配置文件
 * @author zhongyq
 * @version 1.0.0, 2013-3-19
 */
public class SystemProperties {
    // the properties object
    private static Properties props;
    
    /**
     * This method returns the property values, if found. It loads the properties
     * from the map properties file if not already loaded.
     * @param             property        the property whose value is requested for
     * @param             def             the default value to return if property not found
     * @return      String      retVal          the value returned
     */
    public static String getProperty(String property, String def) {
        String retVal = null;
        getProperties();
        if(props != null)
            retVal = props.getProperty(property, def).trim();        
        else
            retVal = def;
        return retVal;
    }
    
    /**
     * @describe: 根据给定的KEY获取配置信息,没有默认返回空字符串
     * @param key
     * @return
     * @author:kui.he
     * @time:2014年9月22日下午12:04:25
     */
   public static String getProperty(String key){
      return getProperty(key,"");
   }
    /**
     * sets the property for the given key & value
     * @param       strKey          String      Key
     * @param       strValue        String      Value
     * @return                      void        
     *
     **/
    public static void setProperty(String strKey, String strValue) {        
        if(props != null)
            props.setProperty(strKey, strValue);
    }

    /**
     * This method loads the properties object and returns it.
     * @return      Properties      the loaded property object, else null
     */
    public static Properties getProperties() {
        if(props == null) {
            try {
                loadProperties("resources.properties");

            }
            catch(Exception exc) {
                System.err.println(exc.getMessage());
                props = null;
            }
        }
        return props;
    }

    /**
     * This method loads the Properties object from the Map Properties file
     * @param             file        the configuration file
     */
    public static void loadProperties(String file) throws Exception {
        props = loadPropertiesFile(file);
    }

    /**
     * This method loads a Properties object and returns it
     * @param             file        the configuration file to load
     */
    public static Properties loadPropertiesFile(String file) throws Exception {

//        String proFile = ConfigUtils.getInstance().getClassPath()+file;
        String path = System.getProperty("global.config.path") == null ? ConfigUtils.getInstance().getClassPath()
                : System.getProperty("global.config.path") ;
        String proFile = path +"/"+file;
        //System.out.println(proFile);
        return ConfigUtils.loadProperties(proFile);

//        Properties retVal = new Properties();
//        String url=SystemProperties.class.getClassLoader().getResource("/")+file;
//        System.out.println("url:"+url);
//        InputStream in = SystemProperties.class.getClassLoader().getResourceAsStream(file);
//        if(in != null)
//            retVal.load(in);
//        in.close();
//        return retVal;
    }
    
    /**
     * 返回类目录路径,如:D:\tools\apache-tomcat-7.0.42\webapps\maps1.1\WEB-INF\classes\
     * 
     * @return
     * @author:kaiqiang.wu
     * @time:2015年11月18日上午10:59:22
     */
    public static String getClassPath(){
       
       return SystemProperties.class.getClassLoader().getResource("").getPath();
       
    }
    
    public static void main(String[] args) {
      System.out.println(SystemProperties.getClassPath());
   }
    
}

三、application-context.xml

<context:property-placeholder location="file:${global.config.path}/resources.properties"/>

四、将配置文件拉取到相应位置:

usr/local/jconfig/resources.properties拉取配置文件到相应的路径;

 

转载于:https://my.oschina.net/u/2322635/blog/1439158

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值