【问题标题】:EJB return null WebsphereEJB 返回空 Websphere
【发布时间】:2016-03-29 23:08:59
【问题描述】:

我正在调整我的应用程序以在 Websphere 8.5.5 中工作,我发现我的应用程序没有注入 EJB,但 Jboss 7.1.1 中的同一个应用程序工作正常。

之后,我创建了一个虚拟应用程序,但它不起作用(仅添加 2 个整数)。

有人可以帮我吗?

已编辑:

package resources;

import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;

import co.com.prueba.local.SumadorLocal;

@ManagedBean
@ViewScoped
public class SumadorUI {

    private Integer a;
    private Integer b;
    private Integer c;

    @EJB
    private SumadorLocal sumadorLocal;

    @PostConstruct
    private void init(){
        System.out.println("Init :"+sumadorLocal);
    }

    public String sumar(){
        c=sumadorLocal.sumador(a, b);
        return null;
    }

    public Integer getA() {
        return a;
    }

    public void setA(Integer a) {
        this.a = a;
    }

    public Integer getB() {
        return b;
    }

    public void setB(Integer b) {
        this.b = b;
    }

    public Integer getC() {
        return c;
    }

    public void setC(Integer c) {
        this.c = c;
    }



}

更新:

我添加新的 EJB 来测试问题注入是在 ManagedBean 中还是在所有应用程序中,并且只有问题是 ManagedBean。

【问题讨论】:

  • 您需要发布一些代码和更具体的观察结果。
  • 仅根据您的标签,我将假设您使用的是 JSF。仅提供的 JSF 实现是 integrated with CDI,因此如果您使用自定义 JSF 库,这可能是原因。提供代码片段和更多描述。如果您使用的是@Inject,请尝试使用@EJB
  • 你是如何创建 SumadorUI 的实例的?
  • 这个实例是由Application Server创建的,这是一个托管bean。

标签: jsf-2 ejb-3.0 websphere-8


【解决方案1】:

经过阅读和测试,我找到了解决方案。在此链接中解释如何创建 DiscoverableInjectionProvider(帮助注入 EJB 实例的类)https://developer.ibm.com/answers/questions/176344/injection-of-stateless-ejbs-‌​into-jsf-managed-beans.html 的实现。使用此类并调整 web.xml 对我有用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多