4

我有两个托管 Bean:

会话豆:

@Named(value = "sessionBean")
@SessionScoped
public class SessionBean implements Serializable {

  private final Param param

  SessionBean(Param param) {
      this.param = param;
  }

}

和 TypesBean:

@Named(value = "typesBean")
@RequestScoped
public class TypesBean {

  @Inject
  private SessionBean session;

}

该项目构建,但不部署:

部署期间发生错误:加载应用程序时出现异常:WELD-001410 注入点 [field] @Inject private com.example.TypesBean.session 具有不可代理的依赖项。有关详细信息,请参阅 server.log。

有什么问题?

4

1 回答 1

9

问题是 SessionBean 类上缺少可访问的无参数构造函数。

OP指出的一种解决方案是:

“问题出在finalSessionBean 的方法中。删除final 和公开方法 - 解决问题。抱歉浪费您的时间。”

或者...

@Named(value = "sessionBean")
@SessionScoped
public class SessionBean implements Serializable {

  . . . //variables, setters, getters and other methods
  private final Param param

  public SessionBean(Param param) {
      this.param = param;
  }
  // no-args constructor used by CDI for proxying only 
  // but is subsequently replaced with an instance 
  // created using the above constructor. 
  protected SessionBean() {
     this(null);
  }
于 2015-12-19T21:24:36.303 回答