CORS Play Framework
<p>I'm developing an Angular 2 application on top of a Play Framework 2.5 (Java) back-end. If I access my endpoints through browser URL, they work fine. However, calling it from the Angular 2 application shows the error:</p>

<blockquote>
  <p>XMLHttpRequest cannot load localhost:9000/app/myendpoint. No
  'Access-Control-Allow-Origin' header is present on the requested
  resource. Origin 'localhost:3000' is therefore not allowed
  access. The response had HTTP status code 500.</p>
</blockquote>

<p>I have tryed to follow the <a href="https://www.playframework.com/documentation/2.5.x/CorsFilter" rel="nofollow noreferrer">documentation</a> and create the filter: </p>

<p>In application.conf:</p>

<pre><code>play.filters {
  cors {
    pathPrefixes = ["/app"]
    allowedOrigins = null
    allowedHttpMethods = null
  }
</code></pre>

<p>Filter:</p>

<pre><code>import play.mvc.*;
import play.api.http.DefaultHttpFilters; &lt;- error with this import
import play.filters.cors.CORSFilter;

public class Filters extends DefaultHttpFilters {
    @Inject public Filters(CORSFilter corsFilter) {
        super(corsFilter);
    }
}
</code></pre>

<p>In build.sbt:</p>

<pre><code>libraryDependencies ++= Seq(
  ...,
  filters
)
</code></pre>

<p>Does anyone knows the true solution? Thank you :)</p>

<p><strong>Working code:</strong></p>

<p>Filters.java (on project's root)</p>

<pre><code>import com.google.inject.Inject;
import com.google.inject.Singleton;    
import play.http.HttpFilters;
import play.mvc.EssentialAction;
import play.mvc.EssentialFilter;
import play.filters.cors.CORSFilter;

@Singleton
public class Filters extends EssentialFilter implements HttpFilters {

    @Inject
    private CORSFilter corsFilter;

    @Override
    public EssentialAction apply(EssentialAction next) {
        return corsFilter.asJava().apply(next);
    }

    @Override
    public EssentialFilter[] filters() {
        EssentialFilter[] result = new EssentialFilter[1];
        result[0] = this;    
        return result;
    }
}
</code></pre>

<p>In application.conf:</p>

<pre><code>  #filters += Filters &lt;- yes, it is commented since my Filters is in project's root
libraryDependencies += filters

play.filters {
 cors{
    # allow all paths
    pathPrefixes = ["/"]
    # allow all origins
    allowedOrigins = null
    allowedHttpMethods = ["GET", "POST", "PUT", "DELETE"]
    # allow all headers
    allowedHttpHeaders = null
} ...
</code></pre>

<p>In build.sbt:</p>

<pre><code>libraryDependencies ++= Seq(
  ...,
  filters
)
</code></pre>

<p>Thank you all! :)</p>