简体   繁体   English

如何在IntellijIDEA 2016中创建简单的RESTful服务? (JAX-RS)

[英]How to create simple RESTful service in IntellijIDEA 2016? (JAX-RS)

My google-fu has failed me. 我的Google Fu使我失败了。

I have lost 2.5 hours trying to figure this out. 我已经花了2.5个小时试图解决这个问题。 I just want to make this simple RESTful service with get and post requests that generate hello world on get (ie localhost:9000/hello ) and on post prints to service console what was sent in bla variable. 我只想使用具有get和post请求的get和post请求制作此简单的RESTful服务(即在localhost:9000 / hello)上以及在向服务控制台发送的bla打印变量上发布的问候。

I have found some simple examples 我找到了一些简单的例子

import javax.ws.rs.GET;
import javax.ws.rs.Path;

@Path("greeting")
public class Greeter {
    @GET
    public String sayHi() {
        return "Hi!!";
    }
}

But it doesn't work intellij doesnt recognize Path and GET annotations. 但这不起作用,IntelliJ无法识别Path和GET批注。 It asks me if I want to implement them. 它询问我是否要实施它们。 I've tried on both NewProj->JavaEE->Restful Web Service and NewProj->Java->WebApp->WebServices. 我已经尝试过NewProj-> JavaEE-> Restful Web Service和NewProj-> Java-> WebApp-> WebServices。

Some sample generated code from one of them made this @webmethod annotation for which I wasn't able to find any info on the net. 从其中之一生成的一些示例代码对此@webmethod进行了注释,但我无法在网上找到任何信息。 And the JetBrains video from 2013 looks like an overkill/a-bit-outdated?. 而2013年的JetBrains 视频看起来像是过大杀伤力/过时了吗? This is really simple app, I don't need/know how to use/ Maven. 这是一个非常简单的应用程序,我不需要/不知道如何使用/ Maven。

You need to download the jar-file containing the classes you have imported (from eg http://download.oracle.com/otndocs/jcp/jaxrs-2_0_rev_A-mrel-spec/index.html ). 您需要下载包含已导入类的jar文件(例如,从http://download.oracle.com/otndocs/jcp/jaxrs-2_0_rev_A-mrel-spec/index.html )。

Open Project Structure, Go to Libraries, press the plus button, and add the jar-file to your project. 打开项目结构,转到库,按加号按钮,然后将jar文件添加到项目中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM