Websphere Liberty配置文件上的JNDI查找失败
我正在IBM J9虚拟机上使用Liberty Profile v8.5.5.5(WebSphere Application Server 8.5.5.5/wlp-1.0.8.CL50520121-0034),版本为pxa6470sr1-20120330_01(SR1)(en_-US) 我已经安装了jndi功能…但是无论我做什么,我都不能进行简单的jndi查找 在my server.xml中Websphere Liberty配置文件上的JNDI查找失败,websphere,jndi,Websphere,Jndi,我正在IBM J9虚拟机上使用Liberty Profile v8.5.5.5(WebSphere Application Server 8.5.5.5/wlp-1.0.8.CL50520121-0034),版本为pxa6470sr1-20120330_01(SR1)(en_-US) 我已经安装了jndi功能…但是无论我做什么,我都不能进行简单的jndi查找 在my server.xml中 <jndiEntry jndiName="schoolOfAthens/defaultAdminUs
<jndiEntry jndiName="schoolOfAthens/defaultAdminUserName" value="plato" />
但这在以下方面失败:
javax.naming.NameNotFoundException:在上下文“serverlocal:CELLROOT/SERVERROOT”中找不到名称schoolOfAthens
代码直接取自一个示例
有什么想法吗
我在本地运行此功能,并在我的Bluemix帐户上进行了尝试。。。同样的结果好的,让它起作用了。我在我的web.xml中添加了一个资源引用,并按如下方式查找:
Object obj2 = ctx.lookup("java:comp/env/schoolOfAthens/defaultAdminUserName");`
web.xml
<resource-ref>
<description>Test Reference</description>
<res-ref-name>schoolOfAthens/defaultAdminUserName</res-ref-name>
<res-auth>Container</res-auth>
</resource-ref>
测试参考
雅典商学院/defaultAdminUserName
容器
同样适用于8.5.5.6,手头没有.5,但应该以同样的方式工作
以下是my server.xml:
<server description="new server">
<!-- Enable features -->
<featureManager>
<feature>servlet-3.1</feature>
<feature>jndi-1.0</feature>
<feature>localConnector-1.0</feature>
</featureManager>
<!-- To access this server from a remote client add a host attribute to the following element, e.g. host="*" -->
<httpEndpoint httpPort="9080" httpsPort="9443" id="defaultHttpEndpoint"/>
<applicationMonitor updateTrigger="mbean"/>
<webApplication id="JNDITest" location="JNDITest.war" name="JNDITest"/>
<jndiEntry jndiName="schoolOfAthens/defaultAdminUserName" value="plato" />
</server>
输出:
object: plato
jndiVariable: plato
你能提供你已经配置的功能列表吗?面对同样的问题,这很有帮助。但我在WLP上也有一些项目,这些项目在不改变web.xml并添加“java:comp/env/”的情况下工作。我无法定义这些项目之间的主要区别。
@WebServlet("/JNDIServlet")
public class JNDIServlet extends HttpServlet {
@Resource(lookup="schoolOfAthens/defaultAdminUserName")
String jndiVariable;
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
try {
InitialContext ctx = new InitialContext();
Object object = ctx.lookup("schoolOfAthens/defaultAdminUserName");
System.out.println("object: " + object);
System.out.println("jndiVariable: " + jndiVariable);
} catch (NamingException e) {
e.printStackTrace();
}
}
}
object: plato
jndiVariable: plato