java - 从 Tomcat 中的 context.xml 中检索资源的方法
问题描述
我想从我的 context.xml 中检索值,我发现了这个代码片段:
// Acquire an instance of our specified bean class
MyBean bean = new MyBean();
// Customize the bean properties from our attributes
Reference ref = (Reference) obj;
Enumeration addrs = ref.getAll();
while (addrs.hasMoreElements()) {
RefAddr addr = (RefAddr) addrs.nextElement();
String name = addr.getType();
String value = (String) addr.getContent();
if (name.equals("foo")) {
bean.setFoo(value);
} else if (name.equals("bar")) {
try {
bean.setBar(Integer.parseInt(value));
} catch (NumberFormatException e) {
throw new NamingException("Invalid 'bar' value " + value);
}
}
}
// Return the customized instance
return (bean);
我想知道是否有一种方法可以做同样的事情但步骤更少
解决方案
Tomcat 8.0 上的 Web 应用程序
推荐阅读
- objective-c - 可可。如何在objective-c中将其他应用程序的特定窗口置于前面
- node.js - 我可以使用 fs 模块和其他模块一起上传文件吗?
- java - 获取 Mongo Repository 中的最新文档
- javascript - 列表上的 React 单击按钮事件始终返回对最后一个元素的引用
- vue.js - Uncaught ReferenceError: then is not defined in Element Ui Plus
- typescript - 如何使用 Jest 调整 Typescript StencilJS 以支持 ES6 动态模块导入
- excel - 需要在一个表上查找名称并将分配的值添加到另一个表中与该名称匹配的所有单元格
- ios - 如何在 SwiftUI 中使用 PageTabViewStyle 摆脱 TabView 上的索引点?
- sql - 在 SQL 视图中使用查找值的最佳方法?
- php - 如何在 PHP 中访问不同(未知)长度的嵌套数组