简体   繁体   中英

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

I joined the eclipse as it says at: https://www.playframework.com/documentation/2.5.x/IDE

And run the command: sbt run It worked. 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 {

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"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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