【发布时间】:2011-12-19 16:21:08
【问题描述】:
我正在使用条纹。我只想添加一些参数,这些参数将在应用程序启动时用于某些配置。最简单(或最好)的方法是什么?属性,web.xml 还是什么?我搜索了条纹书(也是网站),但找不到明确的答案。
我通常会像这样使用 appConfig.properties 文件和监听器类:
public class ConfigLoader implements javax.servlet.ServletContextListener {
public void contextInitialized(ServletContextEvent sce) {
Properties properties = System.getProperties();
properties.put(sce, sce);
try {
properties.load(this.getClass().getResourceAsStream("appConfig.properties"));
System.out.println(this.getClass().getResource("").getFile());
} catch (IOException ex) {
throw new ExceptionAdapter(ex);
}
}
public void contextDestroyed(ServletContextEvent sce) {
throw new UnsupportedOperationException("Not supported yet.");
}
}
【问题讨论】: