我正在根据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:名称[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,但错误是无关的。这是什么问题?
答案 0 :(得分: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。
答案 1 :(得分:1)
默认情况下,为glassfish配置较旧版本的平针织,以使其能够在conf / system.properties中进行设置:
com.sun.jersey.server.impl.cdi.lookupExtensionInBeanManager=true
答案 2 :(得分:1)
BTW为什么不直接使用cxf并让我们部署你的web服务? (=为什么在那里添加球衣,这是不需要的)