【问题标题】:How to inject Session/User object after bootstrapping?引导后如何注入会话/用户对象?
【发布时间】:2016-06-19 11:32:09
【问题描述】:

有一些示例将不同类型的对象注入到演示者中,但我找不到如何做到这一点的解释。

Bootstrap-Code 示例中,他们正在注入例如SecurityDelegate 对象。

同样在Gatekeeper 示例中,我看到注入的东西,例如MyGatekeeper,但是这是怎么做到的呢?

我想要的是首先检查用户是否登录,然后创建一个CurrentSession 对象或类似的东西。但是我怎样才能传递/注入这个对象呢?

目前我正在初始化一个单例对象CurrentUser,这有点难看。我想让 GWTP 支持运行,但是如何运行?


CurrentSession 被注入到网守为例:

@DefaultGatekeeper
public class LoggedInGatekeeper implements Gatekeeper {
    private final CurrentSession currentSession;

    @Inject
    LoggedInGatekeeper(CurrentSession currentSession) {
        this.currentSession = currentSession;
    }

    @Override
    public boolean canReveal() {
        return currentSession.isLoggedIn();
    }
}

如何在这里注入CurrentSession

【问题讨论】:

  • 哇,这个问题在标签完全错误的情况下存活了 20 小时,没有被否决:D 抱歉,我更正了这些标签。
  • 应该被撞。似乎没有人知道或错过了这一点。
  • @EdvinTenovim Nobodoy 知道。极好的! XD
  • 是的... :/ 不幸的是,我也不知道(不知道)。还有这个赏金……如果没了就可惜了。
  • @EdvinTenovim 是的,赏金对我来说并不重要。看到现在似乎没有多少人使用 GWTP 有点困难:/ 这是最糟糕的事情.. ^^

标签: java gwt gwtp gwt-platform


【解决方案1】:

这里有一个说明如何使用 Gatekeeper 的教程:http://dev.arcbees.com/gwtp/tutorials/tutorial-part2.html

在您的 Gin 模块中将 CurrentSession 的类(教程中的 CurrentUser)声明为 Singleton,如下所示:

public class YourGinModule extends AbstractGinModule {

    @Override
    protected void configure() {
        bind( CurrentSession.class ).in ( Singleton.class );
        ...
    }

}

在这里您可以找到另一个在客户端使用 GWTP Gatekeeper 和在服务器端使用 Spring Security 的示例:https://github.com/imrabti/gwtp-spring-security

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-10-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-12
    相关资源
    最近更新 更多