gpt4 book ai didi

jsf - 从托管 bean 访问 ejb 时出现异常

转载 作者:行者123 更新时间:2023-12-02 02:00:49 25 4
gpt4 key购买 nike

由于这个异常,我无法从我的托管 bean(从 jsf 页面使用)访问我的@EJB

javax.ejb.EJBTransactionRequiredException: Transaction is required for invocation: org.jboss.invocation.InterceptorContext@353e531e

jsf 部分(页面 faces-config 和 web.xml)与 beans 部分在不同的包中,但有两个在部署的 EAR 中。本应用部署在jboss 7上

EJB(业务):

@Stateful
@TransactionAttribute(TransactionAttributeType.MANDATORY)
public class DataAccessBusinessImpl implements DataAccessBusiness {

托管 Bean:

public class ConfigurationBean implements Serializable {
@EJB
DataAccessBusiness dab;

Faces-config.xml:

<managed-bean>
<managed-bean-name>configurationBean</managed-bean-name>
<managed-bean-class>ch.morphean.videoaid.lb.managedBean.ConfigurationBean</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>

web.xml:

<display-name>videoaid-site</display-name>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>

谢谢你的帮助

最佳答案

根据 TransactionAttributeType.MANDATORY 的 EJB 规范:

If a client invokes the enterprise bean's method while the client is associated with a transaction context, the container invokes the enterprise bean's method in the client's transaction context. If there is no existing transaction, an exception is thrown.

由于您的“客户端”(托管 bean)没有启动事务,EJB 容器抛出异常,因为您已经使用 TransactionAttributeType.MANDATORY 注释了您的 session bean。

不要使用MANDATORY 作为@TransactionAttribute 的值,而是使用REQUIRED,因为这将强制容器在不存在事务的情况下启动事务。关于 TransactionAttributeType.REQUIRED 的规范说明如下:

If a client invokes the enterprise bean's method while the client is associated with a transaction context, the container invokes the enterprise bean's method in the client's transaction context.

If the client invokes the enterprise bean's method while the client is not associated with a transaction context, the container automatically starts a new transaction before delegating a method call to the enterprise bean method.

关于jsf - 从托管 bean 访问 ejb 时出现异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17269242/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com