WELD-000072声明钝化作用域的托管bean必须具有钝化能力


89

我用Java Web窗体编写了一个简单的程序,但收到以下错误:

WELD-000072声明钝化作用域的托管bean必须具有钝化能力。Bean:BeanPakage.DemoBeans具有限定符[ @Any @Default @Named]的托管Bean [class ]

谁能告诉我这个错误来自哪里?

import javax.enterprise.context.SessionScoped;
import javax.inject.Named;


@Named("DemoBeans")
@SessionScoped
public class DemoBeans {

    private String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}

Answers:


174

您可以通过实现Serializable接口使bean钝化:

public class DemoBean implements Serializable { ... }

请注意,具有钝化能力还有更多要求。有关更多信息,请参阅焊接文档。


20

即使CDI bean是可序列化的,错误也可能仍然存在:

WELD-000072 Managed bean declaring a passivating scope must be passivation capable

示例类:

@Named
@ConversationScoped
public class TransactionMatchController implements Serializable {
    ...
}

确保所有@Interceptor都可以序列化:

@Interceptor
@Transactional
public class TransactionInterceptor implements Serializable {
    ...
}

谢谢,可序列化@Interceptors是我的问题!
Anthony O.


5

使DemoBeans 序列化

@Named("DemoBeans")
@SessionScoped
public class DemoBeans  implements Serializable
{

    private String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

}


1

验证进口

(有时,netbeans使用了其他库中的其他库)

例。导入javax.faces.view.ViewScoped; 通过导入javax.faces.bean.ViewScoped进行更改;


其实JSF 2.3不赞成javax.faces.bean.ViewScoped赞成,javax.faces.view.ViewScoped。这是否意味着我必须遍历所有视图范围的bean并使它们可序列化?来自javax.faces.bean.ViewScopedJavadoc: @deprecated This has been replaced by {@code javax.faces.view.ViewScoped}. The functionality of this corresponding annotation is identical to this one, but it is implemented as a CDI custom scope.
Vasil Svetoslavov

0

由以下原因引起:org.jboss.weld.exceptions.DeploymentException:WELD-000072:声明钝化作用域的Bean必须具有钝化能力。Bean:具有限定符[@Default @Named @Any]的托管Bean [com.marcos.controller.PersonaBean类]


我解决了它,显然是CDI,我没有认出bean,只是让它更明确了

@Named
@ViewScoped
public class PersonaBean  implements Serializable {
@Inject
private IPersonaService service;
public void registrar() {

    try {
        service.registrar(null);

    }catch (Exception e) {
        e.printStackTrace();
    }
  }
}

我的解决方案:

@Named ("PersonaBean")
@ViewScoped
public class PersonaBean  implements Serializable {
@Inject
private IPersonaService service;
public void registrar() {

    try {
        service.registrar(null);

    }catch (Exception e) {
        e.printStackTrace();
    }
  }
}
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.