带 Stripes 的简单应用程序配置
我正在使用条纹。我只想添加一些将在应用程序启动时用于某些配置的参数。最简单(或最好)的方法是什么?属性、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.");
}
}
I'm using Stripes. I just want to add some parameters that will be used at the application start up for some configuration. What is the simplest (or best) way of doing this? Properties, web.xml or what? I searched the stripes book (also website) but couldn't find a clear answer.
I'd normally use an appConfig.properties file and a listener class like this:
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.");
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Stripes 的好处在于,除了装订等小世界之外,它的占地面积并不大。所以你可以做任何你想做的事。如果您对 appConfig.properties 感到满意,那么请务必继续使用它。
The nice thing about Stripes is that beyond it's little world of binding and such, it doesn't have a large footprint. So you can do anything you want. If you're happy with your appConfig.properties, then by all means keep using that.