简体   繁体   English

播放框架Java Rest API示例

[英]play framework java rest api example

I'm starting in the play framework with Java and downloaded the project from the official website: https://github.com/playframework/play-java-rest-api-example/tree/2.5.x 我从Java的播放框架开始,并从官方网站下载了该项目: https//github.com/playframework/play-java-rest-api-example/tree/2.5.x

I joined the eclipse as it says at: https://www.playframework.com/documentation/2.5.x/IDE 我加入了日食, 网址为: https : //www.playframework.com/documentation/2.5.x/IDE

And run the command: sbt run It worked. 并运行命令:sbt run它起作用。 However, if I send a post to the given address, I get the message "Unauthorized". 但是,如果我将帖子发送到给定的地址,则会收到消息“未经授权”。

Does anyone know if I have to do anything else? 有人知道我是否还要做其他事情吗?

Thank you very much in advance. 提前非常感谢您。

在此处输入图片说明

在此处输入图片说明

This is workin for me . 这对我来说是工作。

@Singleton public class Filters implements HttpFilters { @Singleton公共类过滤器实现HttpFilters {

private final Environment env;
private final EssentialFilter exampleFilter;

@Inject
public Filters(Environment env, ExampleFilter exampleFilter) {
    this.env = env;
    this.exampleFilter = exampleFilter;
}

@Override
public EssentialFilter[] filters() {

  if (env.mode().equals(Mode.DEV)) {
      return new EssentialFilter[] { exampleFilter };
  } else {
     return new EssentialFilter[] {};
  }
}

} }

I found out. 我发现。 I have not yet studied Filters, but I left it that way and it worked: 我还没有研究过过滤器,但是我以这种方式离开了,它起作用了: 在此处输入图片说明

另一种方法是在application.conf文件中配置它,只需添加以下行

play.filters.disabled +="play.filters.cors.CORSFilter"

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

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