我正在尝试从2.4迁移到2.5。我在过滤器代码中遇到问题。以下是我的过滤器代码
public class Filters implements HttpFilters {
private final SecurityFilter securityFilter;
@Inject
public Filters(SecurityFilter securityFilter) {
this.securityFilter = securityFilter;
}
@Override
public EssentialFilter[] filters() {
return new EssentialFilter[] {securityFilter.asJava()};
}
}
根据文件https://www.playframework.com/documentation/2.5.x/JavaHttpFilters
asJava()方法可用,并且在带有2.5 jar的eclipse中完美编译。但是当我通过激活器ui或者激活器dist 时,上面的代码失败了。
我已经用下面的内容更新了plugins.sbt addSbtPlugin(" com.typesafe.play"%" sbt-plugin"%" 2.5.1")
但它仍然失败。还有什么应该改变?或者是否有其他配置需要更改?
答案 0 :(得分:0)
当我将我的应用程序从2.4迁移到2.5时,我遇到了同样的问题,我解决了这个问题:
我将过滤器代码更改为:
import play.filters.cors.CORSFilter;
import play.http.DefaultHttpFilters;
import javax.inject.Inject;
public class Filters extends DefaultHttpFilters {
@Inject public Filters(CORSFilter corsFilter) {
super(corsFilter);
}
然后按照文档中的步骤进行操作:Enabling the CORS filter
添加build.sbt
libraryDependencies + = 过滤器
在application.conf中配置cors:
filters{
# CORS filter configuration
cors {
# The path prefixes to filter.
pathPrefixes = ["/json/rest/api"]
# The allowed origins. If null, all origins are allowed.
allowedOrigins = null
# The allowed HTTP methods. If null, all methods are allowed
allowedHttpMethods = ["POST","GET"]
# The allowed HTTP headers. If null, all headers are allowed.
allowedHttpHeaders = null
# The exposed headers
exposedHeaders = []
# Whether to support credentials
supportsCredentials = true
# The maximum amount of time the CORS meta data should be cached by the client
preflightMaxAge = 1 hour
}
随时提出任何问题。