无法解析JMSContext注入

时间:2015-04-10 06:36:30

标签: java jms ejb-3.0 websphere-8

我在我的websphere上创建了一个connectionFactory(qcf / cont)和一个队列(队列/影响) 当我尝试在我的消息驱动bean中注入连接工厂时,我有这个错误:

javax.ejb.EJBException: The @Inject java.lang.reflect.Field.context reference of type javax.jms.JMSContext for the XXXXProducerBean component in the XXXEJB-5.1-SNAPSHOT.jar module of the XXXXServiceEAR application cannot be resolved.
    at com.ibm.wsspi.injectionengine.InjectionBinding.getInjectionObject(InjectionBinding.java:1154) ~[com.ibm.ws.runtime.jar:na]
    at com.ibm.wsspi.injectionengine.InjectionBinding.getInjectableObject(InjectionBinding.java:1032) ~[com.ibm.ws.runtime.jar:na]
    at com.ibm.wsspi.injectionengine.InjectionTarget.inject(InjectionTarget.java:125) ~[com.ibm.ws.runtime.jar:na]
    at com.ibm.ws.injectionengine.AbstractInjectionEngine.inject(AbstractInjectionEngine.java:1084) ~[na:na]
    at com.ibm.ejs.container.StatelessBeanO.initialize(StatelessBeanO.java:289) ~[com.ibm.ws.runtime.jar:na]
    at com.ibm.ejs.container.BeanOFactory.create(BeanOFactory.java:130) ~[com.ibm.ws.runtime.jar:na]
    at com.ibm.ejs.container.EJSHome.createNewBeanO(EJSHome.java:869) ~[com.ibm.ws.runtime.jar:na]
    at com.ibm.ejs.container.EJSHome.createBeanO(EJSHome.java:1242) ~[com.ibm.ws.runtime.jar:na]
    at com.ibm.ejs.container.EJSHome.createBeanO(EJSHome.java:1360) ~[com.ibm.ws.runtime.jar:na]
    at com.ibm.ejs.container.activator.UncachedActivationStrategy.atActivate(UncachedActivationStrategy.java:89) ~[com.ibm.ws.runtime.jar:na]
    at com.ibm.ejs.container.activator.Activator.preInvokeActivateBean(Activator.java:324) ~[com.ibm.ws.runtime.jar:na]
    at com.ibm.ejs.container.EJSContainer.preInvokeActivate(EJSContainer.java:3728) ~[com.ibm.ws.runtime.jar:na]
    at com.ibm.ejs.container.EJSContainer.EjbPreInvoke(EJSContainer.java:3042) ~[com.ibm.ws.runtime.jar:na]

我的mdb看起来像这样:

@Stateless
@Remote({ IXXXX.class })
@Interceptors(SpringBeanAutowiringInterceptor.class)
@TransactionAttribute(TransactionAttributeType.REQUIRED)
@TransactionManagement(TransactionManagementType.CONTAINER)
@DeclareRoles(Constants.USER_ROLE_NAME)
@RolesAllowed(Constants.USER_ROLE_NAME)
public class XXXXProducerBean implements IXXXX {

  @Inject
  @JMSConnectionFactory("qcf/cont")
  private JMSContext context;

  @Resource(name="queue/Impact")
  private Destination queueImpact;

我在互联网上找到的所有文档JMSContext似乎都没有任何配置就被注入了......有什么东西丢失了吗?

修改
感谢Eddie提供的beans.xml文件。我忘了。
但现在我有另外一个例外:

[10/04/15 09:34:55:031 CEST] 0000006e BeansDeployer E BeansDeployer deploy 
                                 javax.enterprise.inject.UnsatisfiedResolutionException: Api type [javax.jms.JMSContext] is not found with the qualifiers 
Qualifiers: [@javax.enterprise.inject.Default()]
for injection into 
 Field Injection Point, field :  private javax.jms.JMSContext com.package.producer.ejb.XXXXProducerBean.context, Bean Owner : [WSEjbBean [businessLocals=[], ejbName=XXXXProducerBean2142018237,Name:null,WebBeans Type:ENTERPRISE,API Types:[java.lang.Object],Qualifiers:[javax.enterprise.inject.Any,javax.enterprise.inject.Default]]
     InjectionType   :  [interface javax.jms.JMSContext]
     Annotated       :  [Annotated Field,Base Type : interface javax.jms.JMSContext,Type Closures : [interface javax.jms.JMSContext, interface java.lang.AutoCloseable, class java.lang.Object],Annotations : [@javax.jms.JMSConnectionFactory(value=qcf/cont), @javax.inject.Inject()],Java Member Name : context]
     Qualifiers      :  [[@javax.enterprise.inject.Default()]]
    at org.apache.webbeans.util.InjectionExceptionUtils.throwUnsatisfiedResolutionException(InjectionExceptionUtils.java:92)

1 个答案:

答案 0 :(得分:0)

WebSphere支持JMS 1.1而非2.0。 @JMSConnectionFactory来自2.0。您需要将其更改为@Resource,如下所示:

@Resource("qcf/cont")
  private ConnectionFactory connectionFactory;