使用@Resource注释的SessionContext注入 [英] SessionContext Injection using @Resource annotation

查看:406
本文介绍了使用@Resource注释的SessionContext注入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要回滚EJB 3无状态SessionBean(CMT,JBoss版本5),我正在使用它

I need to rollback in EJB 3 Stateless SessionBean (CMT, JBoss version 5), for which I am using

sessionContext.setRollbackOnly();

此会话文本使用@Resource注释注入。我的问题:
1)是否首选在EJB3中回滚?

This sessionContext is injected using @Resource annotation. My questions: 1) Is it preferred way to rollback in EJB3?

2)如果我使用公共setter注入,为什么Jboss会在部署时抱怨

2) Why Jboss complains on deployment if I use public setter injection

// throws exception on deployment.
    private SessionContext sessionContext;
    @Resource
    public void setSessionContext(SessionContext sessionContext) {
     this.sessionContext = sessionContext;
    }

但以下工作正常:

@Resource
private SessionContext sessionContext;

以下是第一种情况的例外情况:

Here is the exception in first case:

javax.ejb.SessionContext is an interface, and JAXB can't handle interfaces.
        this problem is related to the following location:
                at javax.ejb.SessionContext
                at public javax.ejb.SessionContext invoice.sap.service.jaxws.SetSctx.arg0
                at invoice.sap.service.jaxws.SetSctx
javax.ejb.SessionContext does not have a no-arg default constructor.
        this problem is related to the following location:
                at javax.ejb.SessionContext


推荐答案

我假设EJB是@WebService,这就是你得到JAXB错误的原因。尝试:

I assume the EJB is an @WebService, which is why you're getting JAXB errors. Try:

@Resource
@WebMethod(exclude=true)
public void setSessionContext(SessionContext sessionContext) {
    this.sessionContext = sessionContext;
}

或者,更改方法可见性或添加最终修饰符(仅限公共非最终的非静态方法是webservices方法)。

Alternatively, change the method visibility or add the final modifier (only public non-final non-static methods are webservices methods).

这篇关于使用@Resource注释的SessionContext注入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆