java - Setting webapprootkey no-web.xml -
i'm migrating web app spring 3.2 , enjoying web.xml-free configuration. 1 part that's remaining setting webapp root key, did in web.xml so:
<context-param> <param-name>webapprootkey</param-name> <param-value>webapproot</param-value> </context-param>
i know spring creates default key, in case i'm running multiple versions of same war , need set key different value in each. optimally i'd take value properties file , use rootkey.
i imagine somewhere here:
public class webappinitializer implements webapplicationinitializer { private static final logger logger = logger.getlogger(webappinitializer.class); @override public void onstartup(servletcontext servletcontext) throws servletexception { // create root appcontext annotationconfigwebapplicationcontext rootcontext = new annotationconfigwebapplicationcontext(); rootcontext.register(appconfig.class); servletcontext.addlistener(new webapprootlistener()); // manage lifecycle of root appcontext servletcontext.addlistener(new contextloaderlistener(rootcontext)); //servletcontext.setinitparameter("defaulthtmlescape", "true"); // main spring mvc servlet. servletregistration.dynamic springapp = servletcontext.addservlet( "springapp", new dispatcherservlet(rootcontext)); springapp.setloadonstartup(1); set<string> mappingconflicts = springapp.addmapping("/"); ...etc...
thanks can offer advice!
the first part simple:
servletcontext.setinitparameter("webapprootkey", getrootkey());
and rootkey, in case added application.properties file maven build,
private string getrootkey() { properties prop = new properties(); classloader loader = thread.currentthread().getcontextclassloader(); inputstream stream = loader.getresourceasstream("application.properties"); string key=null; try { prop.load(stream); key = prop.getproperty("rootkey"); } catch (exception e) { throw new runtimeexception("cannot load webapprootkey", e); } return key; }
Comments
Post a Comment