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

我写了一个简单的程序在 java 网络形式,但我收到以下错误:

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

有人能告诉我这个错误来自哪里吗?

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;
}
}
62950 次浏览

It must be serializable.

See this answer.

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

Best, Anders

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

public class DemoBean implements Serializable { ... }

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

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

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 @Interceptors are seializable as well:

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

Make DemoBeans serialized

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


private String name;


public String getName() {
return name;
}


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


}

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

@Stateful(passivationCapable=true)

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

Regards. Jorge

Verify imports

(some times netbeans used others from others libraries)

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

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]


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

@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();
}
}
}