带 Stripes 的简单应用程序配置

发布于 2024-12-21 22:58:52 字数 782 浏览 1 评论 0原文

我正在使用条纹。我只想添加一些将在应用程序启动时用于某些配置的参数。最简单(或最好)的方法是什么?属性、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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

九八野马 2024-12-28 22:58:52

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文