Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/gwt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 将注入的HttpSession焊接到会话作用域bean中为null_Java_Gwt_Jetty_Cdi_Weld - Fatal编程技术网

Java 将注入的HttpSession焊接到会话作用域bean中为null

Java 将注入的HttpSession焊接到会话作用域bean中为null,java,gwt,jetty,cdi,weld,Java,Gwt,Jetty,Cdi,Weld,我正在用Weld 2.0在Jetty 6.1上运行GWT应用程序。 获得下一个代码: @SessionScoped public class SessionContext implements Serializable { @Inject private HttpSession httpSession; public SessionContext() { super(); //at

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

    @SessionScoped
    public class SessionContext implements Serializable {

        @Inject
        private HttpSession httpSession;

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

我遗漏了什么,为什么没有注入HttpSession?参考说明注入HttpSession将强制创建会话。

更改

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

也可以使用构造函数注入


否则,为
httpSession
提供setter方法来更改

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

也可以使用构造函数注入


否则,请为
httpSession

提供setter方法。最好使用
@PostConstruct
注释其他方法,您可以:

初始化托管bean指定生命周期回调方法 CDI框架应该在依赖项注入之后调用,但是 在课程投入使用之前

这正是您完成注入的地方,但没有调用任何代码

像这样:

@PostConstruct
public void doMyStuff() {
  //feel free to access your injections here they are not null!
}

最好使用
@PostConstruct
注释其他方法,您有:

初始化托管bean指定生命周期回调方法 CDI框架应该在依赖项注入之后调用,但是 在课程投入使用之前

这正是您完成注入的地方,但没有调用任何代码

像这样:

@PostConstruct
public void doMyStuff() {
  //feel free to access your injections here they are not null!
}

谢谢,这很有帮助。但我必须提到,无论如何,必须有一个无参数的默认构造函数。有一个默认的构造函数,并使用
@PostConstruct
方法。谢谢,这很有帮助。但我必须提到,无论如何,必须有一个无参数的默认构造函数。有一个默认的构造函数,并使用
@PostConstruct
方法。