【问题标题】:javax.naming.NameNotFoundException: Name > [com] is not bound in this Context. Unable to find [com]javax.naming.NameNotFoundException:名称 > [com] 未绑定在此上下文中。找不到 [com]
【发布时间】:2016-09-08 09:31:44
【问题描述】:

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

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:名称 [com] 未绑定于此 语境。无法找到 [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,但错误是无关的。这里有什么问题?

【问题讨论】:

    标签: tomcat jersey jax-rs


    【解决方案1】:

    我不知道你用的是哪个版本的球衣,所以我考虑最后一个。尝试更改 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

    【讨论】:

      【解决方案2】:

      旧版本的 jersey 默认配置为 glassfish,要使其在 tomee 中工作,您需要在 conf/system.properties 中进行设置:

      com.sun.jersey.server.impl.cdi.lookupExtensionInBeanManager=true
      

      【讨论】:

        【解决方案3】:

        顺便说一句,为什么不直接使用 cxf 并让 tomee 部署您的 Web 服务? (= 为什么要在那里添加球衣,这不是必需的)

        【讨论】:

          猜你喜欢
          • 2013-05-20
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2018-11-02
          • 2017-07-17
          • 2012-10-07
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多