如何在Websphere 7 JNDI中配置字符串值? [英] How to configure a String value in Websphere 7 JNDI?
问题描述
事实上,我之前发现过这样的消息: 通过JNDI在以下位置配置和查找简单的字符串WebSphere
In fact I found such message before: Configuring and looking up a simple String via JNDI in WebSphere
我想采用干净"的方式( http ://www.ibm.com/developerworks/websphere/library/techarticles/0611_totapally/0611_totapally.html ).也许我对WebSphere太绿了,但是这篇文章完全弄乱了我的想法,因为它显示了一个更复杂的示例.
I want to do the "clean" way (http://www.ibm.com/developerworks/websphere/library/techarticles/0611_totapally/0611_totapally.html). Maybe I am simply too green on WebSphere, my mind is totally messed up by the article because it is showing a more complicated example.
有人可以给我一些有关如何配置WebSphere的简短步骤,以便我可以在JNDI中绑定String值吗?非常感谢
Can someone give me a brief steps on how to configure WebSphere so that I can bind a String value in JNDI? Thanks so much
推荐答案
好吧,假设您要存储的是一个"configuration"元素,我实际上会花点时间并使用Resource Environment Providers来实现它,因为它是更灵活,而且显然更可移植的方法.
Well, assuming that what you want to store is a "configuration" element, I'd actually take the time and implement it using Resource Environment Providers as it's a more flexible, and obviously more portable, approach.
In order to bind a String using JNDI, use "String Namespace Bindings": http://pic.dhe.ibm.com/infocenter/wasinfo/v7r0/topic/com.ibm.websphere.nd.doc/info/ae/ae/unam_rstring_namespace.html
已编辑(以添加有关ResEnv的详细信息):
Edited (to add details about ResEnv):
工厂类是您编写的类,而不是IBM.这是一个示例:
The factory class is a class that you write, not IBM. Here's an example for one:
public class MyFactory implements javax.naming.ObjectFactory {
@Override
public Object getObjectInstance(Object object, Name name, Context context, Hashtable env) throws NamingException {
MyConfig cfg = new MyConfig();
for (Enumeration e = ((Reference) object).getAll(); e.hasMoreElements();) {
RefAddr addr = (RefAddr) e.nextElement();
String key = addr.getType();
Object value = addr.getContent();
cfg.put(key, value);
}
}
}
(我们假设MyConfig
是具有get(String)
和put(String, String)
方法的简单类)
(We're assuming that MyConfig
is a simple class with get(String)
and put(String, String)
methods)
接下来,在WebSphere中创建一个新的Resource Environment Provider.对于Referenceable,请将MyFactory的完全合格的类名称作为工厂类",而将MyConfig的完全合格的类名称作为类".
Next, create a new Resource Environment Provider in WebSphere. For a Referenceable, put the fully-qualified class name of MyFactory as the "factory class" and the fully-qualified class name of MyConfig as the "class".
接下来,添加一个资源环境"条目.为它指定一个JNDI名称,例如myresources/test
.从下拉框中选择可引用".
Next, add a Resource Environment entry. Give it a JNDI name, say myresources/test
. Select the Referenceable from the dropdown box.
点击自定义属性",然后在其中添加键值对.
Click "Custom Properties", and add key-value pairs there.
保存WebSphere配置,重新启动服务器,然后重试.发出对myresources/test
的JNDI查找,您将获得一个MyConfig
实例,其中包含您放置在其中的所有自定义属性.
Save the WebSphere configuration, restart your server and try again. Issue a JNDI lookup to myresources/test
, and you'll get a MyConfig
instance with all the custom properties you placed there.
让我们知道进展如何.祝你好运!
Let us know how it went. Good luck!
这篇关于如何在Websphere 7 JNDI中配置字符串值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!