単一モードの実用化


           ,         ,             。
                 ?

          ,           ,        ,                 ,                  。
                  ,          ,           。                ,                    ,         。
            ,            ,             ,     ,               ,         ,               new  ,      ,                 ,                                ,                          ,           ,         ,               ,                 ,                   。

   ; ; ;[ http://www.cnblogs.com/seesea125/archive/2012/04/05/2433463.html ]

, , , 。

1、spring
public class UserConfigListener extends ContextLoaderListener {



    protected final Log logger = LogFactory.getLog(getClass());



    public void contextInitialized(ServletContextEvent event) {

        try {

            Config.getInstance().init();

        } catch (Exception e) {

            logger.error("       :", e);

        }

    }

    

}
2、    
public class Config {

    private static Config instance = new rConfig();

    private Map<String, String> info = new HashMap<String, String>();



    //       

    public static Config getInstance() {

        return instance;

    }



    //       

    private Config() {

    }



    public void init() throws Exception {

        info.put("aa","bb");

    }



    public Map<String, String> getUInfo() {

        return info;

    }



}
             ,       ,          ,                    。       ,o(∩_∩)o