Java Playframework GlobalSettings弃用onStart

Java Playframework GlobalSettings弃用onStart,第1张

Java Playframework GlobalSettings弃用onStart

您需要两个类-一个用于处理初始化的类,以及一个用于注册绑定的模块

初始化代码:

@Singletonpublic class onStartup {    @Inject    public onStartup(final UserService userService) {        if (userService.findUserByEmail("[email protected]") == null) { String email = "[email protected]"; String password = "1234"; String fullName = "My Name"; User user = new User(); user.password = BCrypt.hashpw(password, BCrypt.gensalt()); user.full_name = fullName; user.email = email; user.save();        }    }}

模块:

public class onStartupModule extends AbstractModule {    @Override    public void configure() {        bind(OnStartup.class).asEagerSingleton();    }}

最后,将模块添加到中

application.conf

play.modules.enabled += "com.example.modules.OnStartupModule"

通过使单身人士渴望,它将在应用程序启动时运行。



欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5601347.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-15
下一篇 2022-12-15

发表评论

登录后才能评论

评论列表(0条)

保存