tomcat - javax.naming.NameNotFoundException : Name > [com] is not bound in this Context. 无法找到 [com]

标签 tomcat jersey jax-rs

我正在从动态 Web 项目类型开发一个简单的 Jersey Web 服务,遵循 this教程。到目前为止,我有以下代码:

ServiceStatus.Java(在包 au.com.biting.bolat.status 中)

package au.com.biting.bolat.status;

import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;

@Path("/v1/status")
public class ServiceStatus {

    @GET
    @Produces(MediaType.TEXT_HTML)
    public String returnTitle() {
        return "<p>Java Web Service</p>";
    }

}

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>au.com.biting.bolat</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>


  <servlet>
    <servlet-name>Jersey REST Service</servlet-name>
    <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
    <init-param>
      <param-name>com.sun.jersey.config.property.packages</param-name>
      <param-value>au.com.biting.bolat</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>Jersey REST Service</servlet-name>
    <url-pattern>/api/*</url-pattern>
  </servlet-mapping>
  </web-app>

当我在 tomEE 中运行此服务时,根路径 ( http://localhost:8080/au.com.biting.bolat/ ) 工作正常,但路径 http://localhost:8080/au.com.biting.bolat/api/v1/status 出现以下错误:

javax.naming.NameNotFoundException: Name [com] is not bound in this Context. Unable to find [com]. org.apache.naming.NamingContext.lookup(NamingContext.java:819) org.apache.naming.NamingContext.lookup(NamingContext.java:167) org.apache.naming.SelectorContext.lookup(SelectorContext.java:156) javax.naming.InitialContext.lookup(InitialContext.java:417) com.sun.jersey.server.impl.cdi.CDIExtension$2.stepInto(CDIExtension.java:308) com.sun.jersey.server.impl.cdi.CDIExtension.diveIntoJNDIContext(CDIExtension.java:285) com.sun.jersey.server.impl.cdi.CDIExtension.lookupJerseyConfigJNDIContext(CDIExtension.java:305) com.sun.jersey.server.impl.cdi.CDIExtension.getInitializedExtension(CDIExtension.java:181) com.sun.jersey.server.impl.cdi.CDIComponentProviderFactory.(CDIComponentProviderFactory.java:95) com.sun.jersey.server.impl.cdi.CDIComponentProviderFactoryInitializer.initialize(CDIComponentProviderFactoryInitializer.java:76) com.sun.jersey.spi.container.servlet.WebComponent.configure(WebComponent.java:572) com.sun.jersey.spi.container.servlet.ServletContainer$InternalWebComponent.configure(ServletContainer.java:332) com.sun.jersey.spi.container.servlet.WebComponent.load(WebComponent.java:604) com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:207) com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:394) com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:577) javax.servlet.GenericServlet.init(GenericServlet.java:158) org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:44) org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505) org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103) org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956) org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:436) org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1078) org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625) org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316) java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) java.lang.Thread.run(Thread.java:745)

我尝试了几种修复方法,包括清理和构建项目、从头开始构建项目并检查了 this similar question ,但错误是无关的。这里有什么问题?

最佳答案

我不知道你用的是哪个版本的 Jersey ,所以我考虑最后一个。尝试更改 web.xml 中某些属性的名称,因为您使用的是旧的,教程有点旧:

...
<servlet>
    <servlet-name>Jersey REST Service</servlet-name>
    <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
    <init-param>
        <param-name>jersey.config.server.provider.packages</param-name>
        <param-value>au.com.biting.bolat</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>
...

更多详情可以访问official documentation .

关于tomcat - javax.naming.NameNotFoundException : Name > [com] is not bound in this Context. 无法找到 [com],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39387360/

相关文章:

java - 如何使用 Java 在 Eclipse 中使用 Web 服务(JAX - RS)从数据库中检索数据

html - 在 Eclipse IDE 之外使用 JSP 文件

macos - 在 mac os 上托管 tomcat

apache - 使用 Tomcats(在 apache-tomcat 集群中)作为后面的 apache 服务器的反向代理

java - 找不到 Java 类 java.util.ArrayList 和 MIME 媒体类型 application/json 的消息正文编写器

java - Dropwizard/JAX-RS 1.x (JSR 311) 中的资源链接

java - 关于 JAX-RS 中的可选路径

jax-rs - 如何在 JAX-RS 过滤器中记录请求处理时间

java - JAX-RS 注释 : Better to put on Interfaces or Classes?

java - Tomcat 无效的 lib 目录