gpt4 book ai didi

websphere - OpenLiberty NameNotFoundException : java:/comp/env

转载 作者:行者123 更新时间:2023-12-04 01:58:04 37 4
gpt4 key购买 nike

我有一个在 Tomcat 中正确运行的 Web 应用程序,我想在新的 OpenLiberty 服务器上运行,该应用程序在 OpenLiberty 中正确启动,但在数据库连接启动时抛出以下异常:

[Default Executor-thread-15] 2018-03-15 15:02:30 ERROR TomcatConnectionManager:41 - Loading jdbc/mysql/myaap failure
javax.naming.NameNotFoundException: java:/comp/env
at com.ibm.ws.jndi.url.contexts.javacolon.internal.JavaURLName.<init>(JavaURLName.java:83)
at com.ibm.ws.jndi.url.contexts.javacolon.internal.JavaURLNameParser.parse(JavaURLNameParser.java:39)
at com.ibm.ws.jndi.url.contexts.javacolon.internal.JavaURLNameParser.parse(JavaURLNameParser.java:60)
at com.ibm.ws.jndi.url.contexts.javacolon.internal.JavaURLContext$NameUtil.<init>(JavaURLContext.java:474)
at com.ibm.ws.jndi.url.contexts.javacolon.internal.JavaURLContext.lookup(JavaURLContext.java:321)
at com.ibm.ws.jndi.url.contexts.javacolon.internal.JavaURLContext.lookup(JavaURLContext.java:370)
at org.apache.aries.jndi.DelegateContext.lookup(DelegateContext.java:161)

上面的异常是在查找阶段抛出的:

Context initContext = new InitialContext();
Context envContext = (Context) initContext.lookup("java:/comp/env");

有没有什么方法可以让它在 OpenLiberty 上工作,尽可能少做改动?

最佳答案

在 OpenLiberty 上,等效的查找看起来像这样:

    Context initContext = new InitialContext();
Context envContext = (Context) initContext.lookup("java:comp/env");

关键是你需要使用java:comp/...而不是java:/comp/...


Tomcat 之所以不同于 Liberty,是因为 Tomcat 只是一个 servlet 容器,而 Liberty 符合完整的 Java EE 规范。

根据 EE.5.2.2 of the Java EE 7 spec 部分:

The application component’s naming environment is composed of four logical namespaces, representing naming environments with different scopes. The four namespaces are:

  • java:comp – Names in this namespace are per-component (for example, per enterprise bean). Except for components in a web module, each component gets its own java:comp namespace, not shared with any other component. Components in a web module do not have their own private component namespace. See note below.
  • java:module – Names in this namespace are shared by all components in a module (for example, all enterprise beans in a single EJB module, or all components in a web module).
  • java:app – Names in this namespace are shared by all components in all modules in a single application, where “single application” means a single deployment unit, such as a single ear file, a single module deployed standalone, etc. For example, a war file and an EJB jar file in the same ear file would both have access to resources in the java:app namespace.
  • java:global – Names in this namespace are shared by all applications deployed in an application server instance. Note that an application server instance may represent a single server, a cluster of servers, an administrative domain containing many servers, or even more. The scope of an application server instance is product-dependent, but it must be possible to deploy multiple applications to a single application server instance.

关于websphere - OpenLiberty NameNotFoundException : java:/comp/env,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49302912/

37 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com