gpt4 book ai didi

java - 将 HttpSession Weld 到 session 作用域 bean 中时为 null

转载 作者:太空宇宙 更新时间:2023-11-04 07:43:39 24 4
gpt4 key购买 nike

我正在 Jetty 6.1 上使用 Weld 2.0 运行 GWT 应用程序。得到下一个代码:

    @SessionScoped
public class SessionContext implements Serializable {

@Inject
private HttpSession httpSession;

public SessionContext() {
super();
//at this point httpSession is null
}
}

我缺少什么,为什么 HttpSession 没有注入(inject)?引用文献说注入(inject) HttpSession 将强制创建 session 。

最佳答案

更改定义

public SessionContext() {
super();
//at this point httpSession is null
}

public SessionContext(HttpSession httpSession) {
super();
this.httpSession = httpSession;
//check session here
}

还使用构造函数注入(inject)

否则为httpSession提供setter方法

关于java - 将 HttpSession Weld 到 session 作用域 bean 中时为 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15657861/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com