从2.4升级后,Formatters.register编译错误

时间:2016-07-04 17:11:31

标签: formatter playframework-2.5

我得到那些奇怪的,非静态的'当我运行'激活器编译时,从2.4升级到2.5后出现错误:

2222

XptoConverter:

non-static method  <T>register(java.lang.Class<T>,play.data.format.Formatters.SimpleFormatter<T>) cannot be referenced from a static context

public MyController() {
    Formatters.register(Xpto.class, new XptoConverter());
}

1 个答案:

答案 0 :(得分:2)

这些方法不再是静态的;注入Formatter。见https://www.playframework.com/documentation/2.5.x/JavaForms#Register-a-custom-DataBinder。另请参阅https://github.com/playframework/playframework/pull/5734

你必须

  1. 创建public class FormattersProvider implements Provider<Formatters>(进行转化)
  2. 创建public class FormattersModule extends AbstractModule
  3. 启用FormattersModule
  4. 中的application.conf