- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我已经看过很多教程,但我无法让我的简单 JAX-RS 应用程序工作。 Tomcat 总是返回错误 404。
获取类(class)的申请:
package api;
import java.util.HashSet;
import java.util.Set;
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;
@ApplicationPath("/resources")
public class MyApplication extends Application {
// All request scoped resources and providers
@Override
public Set<Class<?>> getClasses() {
Set<Class<?>> classes = new HashSet<>();
classes.add(AuthenticationEndpoint.class);
return classes;
}
}
我的 JAX-RS 文件:
package api;
@Path("/hello")
public class AuthenticationEndpoint {
@GET
public Response getUser() {
return Response.status(200).entity("getUser is called").build();
}
}
网络.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1">
<display-name>MSM-Master</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>MyApplication</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>api</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>MyApplication</servlet-name>
<url-pattern>/resources</url-pattern>
</servlet-mapping>
</web-app>
在“Web 项目设置”下,我的上下文根是:“MSM-Master”
我尝试调用的 url 是:
http://localhost:8080/MSM-Master/resources/hello/
编辑:添加了 Tomcat 控制台输出:
Dez 14, 2017 4:32:39 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNUNG: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:MSM-Master' did not find a matching property.
Dez 14, 2017 4:32:39 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: Server version: Apache Tomcat/8.0.30
Dez 14, 2017 4:32:39 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: Server built: Dec 1 2015 22:30:46 UTC
Dez 14, 2017 4:32:39 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: Server number: 8.0.30.0
Dez 14, 2017 4:32:39 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: OS Name: Windows 7
Dez 14, 2017 4:32:39 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: OS Version: 6.1
Dez 14, 2017 4:32:39 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: Architecture: amd64
Dez 14, 2017 4:32:39 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: Java Home: C:\Program Files\Java\jre1.8.0_66
Dez 14, 2017 4:32:39 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: JVM Version: 1.8.0_66-b18
Dez 14, 2017 4:32:39 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: JVM Vendor: Oracle Corporation
Dez 14, 2017 4:32:39 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: CATALINA_BASE: C:\Users\u016975\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0
Dez 14, 2017 4:32:39 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: CATALINA_HOME: C:\Program Files\Apache Software Foundation\Tomcat 8.0
Dez 14, 2017 4:32:39 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: Command line argument: -Dcatalina.base=C:\Users\u016975\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0
Dez 14, 2017 4:32:39 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: Command line argument: -Dcatalina.home=C:\Program Files\Apache Software Foundation\Tomcat 8.0
Dez 14, 2017 4:32:39 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: Command line argument: -Dwtp.deploy=C:\Users\u016975\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps
Dez 14, 2017 4:32:39 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: Command line argument: -Djava.endorsed.dirs=C:\Program Files\Apache Software Foundation\Tomcat 8.0\endorsed
Dez 14, 2017 4:32:39 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: Command line argument: -Dfile.encoding=Cp1252
Dez 14, 2017 4:32:39 PM org.apache.catalina.core.AprLifecycleListener lifecycleEvent
INFORMATION: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jre1.8.0_66\bin;C:\windows\Sun\Java\bin;C:\windows\system32;C:\windows;C:/Program Files/Java/jre1.8.0_66/bin/server;C:/Program Files/Java/jre1.8.0_66/bin;C:/Program Files/Java/jre1.8.0_66/lib/amd64;C:\ProgramData\Oracle\Java\javapath;C:\Program Files (x86)\Java\jdk1.8.0_66\bin;C:\Program Files\Git\cmd;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\Users\u016975\AppData\Roaming\npm\;C:\Users\u016975\apache-ant-1.9.7\bin;C:\Users\u016975\AppData\Local\Android\android-sdk\tools;C:\Users\u016975\AppData\Local\Android\android-sdk\platform-tools;C:\windows\system32; C:\windows; C:\windows\System32\Wbem;C:\Applications\Atlassian\atlassian-plugin-sdk-6.2.14\bin;C:\Users\u016975\AppData\Local\Apps\cURL\bin;C:\Applications\Atlassian\atlassian-plugin-sdk-6.2.15\bin;node_modules\npm;C:\Program Files\nodejs\;C:\Users\u016975\apache-ant-1.9.7\bin;C:\Users\u016975\AppData\Local\Android\android-sdk\tools;C:\Users\u016975\AppData\Local\Android\android-sdk\platform-tools;C:\windows\system32; C:\windows; C:\windows\System32\Wbem;C:\Applications\Atlassian\atlassian-plugin-sdk-6.2.14\bin;C:\Users\u016975\AppData\Local\Apps\cURL\bin;C:\Applications\Atlassian\atlassian-plugin-sdk-6.2.15\bin;node_modules\npm;C:\Users\u016975\AppData\Roaming\npm;C:\Program Files\Microsoft VS Code\bin;C:\Users\u016975\Downloads\eclipse-jee-mars-1-win32-x86_64\eclipse;;.
Dez 14, 2017 4:32:39 PM org.apache.coyote.AbstractProtocol init
INFORMATION: Initializing ProtocolHandler ["http-nio-8080"]
Dez 14, 2017 4:32:39 PM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFORMATION: Using a shared selector for servlet write/read
Dez 14, 2017 4:32:39 PM org.apache.coyote.AbstractProtocol init
INFORMATION: Initializing ProtocolHandler ["ajp-nio-8009"]
Dez 14, 2017 4:32:39 PM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFORMATION: Using a shared selector for servlet write/read
Dez 14, 2017 4:32:39 PM org.apache.catalina.startup.Catalina load
INFORMATION: Initialization processed in 621 ms
Dez 14, 2017 4:32:39 PM org.apache.catalina.core.StandardService startInternal
INFORMATION: Starting service Catalina
Dez 14, 2017 4:32:39 PM org.apache.catalina.core.StandardEngine startInternal
INFORMATION: Starting Servlet Engine: Apache Tomcat/8.0.30
Dez 14, 2017 4:32:46 PM org.apache.jasper.servlet.TldScanner scanJars
INFORMATION: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
Dez 14, 2017 4:32:46 PM org.apache.catalina.core.StandardContext startInternal
SCHWERWIEGEND: Error during ServletContainerInitializer processing
javax.servlet.ServletException: java.lang.InstantiationException: org.glassfish.tyrus.server.TyrusServerConfiguration
at org.apache.tomcat.websocket.server.WsSci.onStartup(WsSci.java:88)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5244)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1408)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1398)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.InstantiationException: org.glassfish.tyrus.server.TyrusServerConfiguration
at java.lang.Class.newInstance(Unknown Source)
at org.apache.tomcat.websocket.server.WsSci.onStartup(WsSci.java:74)
... 8 more
Caused by: java.lang.NoSuchMethodException: org.glassfish.tyrus.server.TyrusServerConfiguration.<init>()
at java.lang.Class.getConstructor0(Unknown Source)
... 10 more
Dez 14, 2017 4:32:46 PM org.apache.catalina.core.StandardContext startInternal
SCHWERWIEGEND: Context [/MSM-Master] startup failed due to previous errors
Dez 14, 2017 4:32:46 PM org.apache.coyote.AbstractProtocol start
INFORMATION: Starting ProtocolHandler ["http-nio-8080"]
Dez 14, 2017 4:32:46 PM org.apache.coyote.AbstractProtocol start
INFORMATION: Starting ProtocolHandler ["ajp-nio-8009"]
Dez 14, 2017 4:32:46 PM org.apache.catalina.startup.Catalina start
INFORMATION: Server startup in 6457 ms
最佳答案
@ApplicationPath
由 JAX – RS
提供,用于开发没有 web.xml
的 restful web 服务应用程序。所以你可以删除你的web.xml
然后尝试覆盖 getProperties
@ApplicationPath("/resources")
public class MyApplication extends Application {
// All request scoped resources and providers
@Override
public Set<Class<?>> getClasses() {
Set<Class<?>> classes = new HashSet<>();
classes.add(AuthenticationEndpoint.class);
return classes;
}
@Override
public Map<String, Object> getProperties() {
final Map<String, Object> properties = new HashMap<>();
properties.put("jersey.config.server.provider.packages",
"api");//api-->here mention your yourpackage.to.scan"
return properties;
}
}
关于java - TomCat 上的 JAX-RS 总是返回 404,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47816101/
来自 JSR-339: For simplicity, JAX-RS implementations are NOT REQUIRED to support processing groups oth
JAX-RS 提供了 StreamingOutput 接口(interface),我们可以实现它来对我们的响应主体进行原始流处理。 public interface StreamingOutput {
有没有办法获得java.lang.reflect.Method为给定的 @Path 调用的方法(用 HttpServletRequest 注释) ? 这是我的用例:我在 Java EE 中 Filte
我接到了一家公司的任务,该任务向我发送了一台已完成所有设置的虚拟机。任务是我必须创建一个 API 来从数据库中检索人员详细信息并显示它。 问题是,当我运行应用程序时,服务器返回一个包含 hello w
我有一个 POST 方法调用,它接受很少的表单参数。我希望 JAX-RS 能够处理不存在特定表单参数的情况。 示例: @POST @Produces (MediaType.APPLICATION_JS
我有 JAX-RS 网络应用程序,我想记录从获取请求到响应的时间量。在带有 servlet 过滤器的 Spring Boot 中很容易。但是我的应用程序中的过滤器无法正常工作: @Provider p
使用以下网址。 http://doma.in/context/resource/some/.../undefined 我想获取 ../resource 之后的路径名,即 /some/.../undef
Closed. This question is off-topic。它当前不接受答案。
我花了几个小时在嵌入式 Jetty 9.1.0.v20131115 和 RESTEasy 3.0.5.Final 中安装自定义登录服务。我的登录服务将在数据库中查找用户并为他们分配角色。它看起来像这样
RESOURCE_STALLS.RS的说明Intel Broadwell 的硬件性能事件如下: This event counts stall cycles caused by absence of
我想从 java 服务器 (Restful Jax-rs) 发送图像。我的客户是安卓。 @GET public Response getUserImage() { byte[] image =new
(特别是 RESTeasy) 具有如下方法签名会很好(对于单个文件): public void upload(@FormParam("name") ..., @FormParam("file") fi
RESTEasy (JAX-RS) 允许通过子资源进行动态调度。例如: POST /customers/create {"name":"Smith","country":"jp"} 我们可以有一个根资
假设有一个 ResultSet rs 和 n 对象。 这段代码: while(rs.next()) { // do something on rs } 在算法上等于此代码(即两者给出相同的结果)
我正在使用 Visual Studio 2005 和 mysql 4.0,我有一个表,其中包含一个字段(十进制 16,4),用于存储发票金额和另一个表,其中包含对该发票的付款(这些字段也是十进制的)
我正在使用 JAX-RS、Microprofile 和 Payara 5 构建 REST 服务。我的方法返回类型为 Response 的对象。响应本身包含一个 MyClass 列表。实现看起来像这样:
我已经使用 Mock MVC 成功地为 Spring MVC REST 服务构建了无需部署的集成测试框架。我正在努力对 JAX-RS 服务做同样的事情。 REST Assured 看起来很有希望,但它
我有一个使用JAX-RS 2.0的Jersey实现的Java应用程序,并且我想在客户端启用gzip压缩。服务器已启用它,并且通过在Chrome中的开发人员工具中的“大小/内容”中查找客户端正在使用的特
我正在尝试与 Tomcat7 一起使用 RESTful Web 服务 (JAX-RS)。我尝试了 3 种不同的实现(Jersey、RESTeasy 和 ReSTLet),但都没有成功。这应该很容易,但
swagger-api有什么区别和 JAX-RS ? 是swagger-api仅用于文档? (例如 @ApiOperation ) 最佳答案 根据 API 文档,JAX-RS是用于 RESTful W
我是一名优秀的程序员,十分优秀!