Java WELD-000072 声明钝化范围的托管 bean 必须具有钝化能力

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9760442/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-16 07:20:25  来源:igfitidea点击:

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

javacdijboss-weld

提问by christina

I wrote a simple program in java web forms but i am receiving the following error:

我用 java web 表单编写了一个简单的程序,但收到以下错误:

WELD-000072 Managed bean declaring a passivating scope must be passivation capable. Bean: Managed Bean [class BeanPakage.DemoBeans] with qualifiers [@Any@Default@Named]

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

Can anyone tell me where this error comes from?

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

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;
    }
}

采纳答案by Matt Handy

You can make your bean passivation capable by implementing the Serializable interface:

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

public class DemoBean implements Serializable { ... }

Note that there are more requirements for being passivation capable. Refer to the Weld documentation for more information.

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

回答by anders.norgaard

It must be serializable.

它必须是可序列化的。

See this answer.

看到这个答案。

https://community.jboss.org/thread/179828

https://community.jboss.org/thread/179828

Best, Anders

最好的,安德斯

回答by Tim

The error might remain even though the CDI bean is serializable:

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

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

Example class:

示例类:

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

Make sure that all @Interceptorsare seializable as well:

确保所有@Interceptors也是可密封的:

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

回答by Mohd Kose Avase

Make DemoBeansserialized

进行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;
    }

}

回答by Jorge Torres

You can also activate passivation behavior of your bean with the annotation:

您还可以使用注释激活 bean 的钝化行为:

@Stateful(passivationCapable=true)

@Stateful(passivationCapable=true)

In this case you don't need to implement Serializable interface.

在这种情况下,您不需要实现 Serializable 接口。

Regards. Jorge

问候。乔治

回答by Fabian Pisani

Verify imports

验证导入

(some times netbeans used others from others libraries)

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

Example. import javax.faces.view.ViewScoped; change it by import javax.faces.bean.ViewScoped;

例子。导入 javax.faces.view.ViewScoped; 通过 import javax.faces.bean.ViewScoped 更改它;

回答by Marcos Chacaliaza Altamirano

Caused by: org.jboss.weld.exceptions.DeploymentException: WELD-000072: Bean declaring a passivating scope must be passivation capable. Bean: Managed Bean [class com.marcos.controller.PersonaBean] with qualifiers [@Default @Named @Any]

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



I solved it, apparently CDI,I did not recognize the bean, I just made it more explicit

我解决了,显然是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();
    }
  }
}

the solution for me:

我的解决方案:

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

    try {
        service.registrar(null);

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