常量(Constant)的存放

在一个系统中,系统级、模块级以及Bean级的常量都是必须的,看实际情况决定存放的位置。

常量的意思,就是static 和 final,要求可以Constants.xxxx这样的静态方式简便获取,而且该变量是不可修改的,否则比较容易混乱。

但有时候又希望Contants除了重新编译以外,提供其他的配置方式不编译源码而配置。因此SpringSide扩展了ConfigurableContants基类。子类如 org.springside.framework.Constants如下:

public class Constants extends ConfigurableContants {
static {
        init("springside.properties");
    }

//ERROR_BUNDLE_KEY常量,默认值为"errors"
public final static String ERROR_BUNDLE_KEY = getProperty("constant.error_bundle_key", "errors");
 
}

   必须静态的执行init初始化函数,指定读入的properties文件名

  然后就可以用getProperty(String key, String defaultValue)函数尝试读取常量,如果读不到则赋予默认值defaultValue。