samedi 21 mars 2015

How to set global config/variable in Spring MVC 4?

I am using Spring MVC 4.1.4


I have some global settings to share in whole application


These setting should only be loaded when start the server


I know I can use context-param



<context-param>
<param-name>configA</param-name>
<param-value>valueA</param-value>
</context-param>
<context-param>
<param-name>configB</param-name>
<param-value>valueB</param-value>
</context-param>


But I want store some complex object, like this



HashMap myConfig = new HashMap();

String[] cfgB={"b1", "b2"};

HashMap<String, String> cfgC=new HashMap<String, String>();
cfgC.put("C1", "1");
cfgC.put("C2", "2");

MyConfigD cfgD = new MyConfigD();

myConfig.put("configA", "A");
myConfig.put("configB",cfgB);
myConfig.put("configC",cfgC);
myConfig.put("configD",cfgD);


context-param is not possible to do that, what else I can use in Java or Spring?


Aucun commentaire:

Enregistrer un commentaire