Weblogic 10.3 MDB抛出javax.sql.DataSource异常

时间:2010-07-01 00:45:45

标签: java java-ee ejb-3.0 weblogic-10.x message-driven-bean

以下是我正在使用的应用程序:

  1. Weblogic 10.3.3
  2. Websphere MQ 7.0
  3. Oracle 11g Express Edition(DB)
  4. 这是当前的流程:

    1. Weblogic从Websphere MQ队列读取消息并由MDB处理
    2. MDB将消息保存到数据库
    3. MDB将消息写入另一个Websphere MQ队列
    4. 这是一个XA事务,因此如果上述任何操作失败,该消息将返回到原始队列。

      当我在Websphere MQ队列上放置一条消息以启动进程时出现错误:

      <Jun 29, 2010 11:15:15 PM CDT> <Error> <EJB> <BEA-010080> <An error occurred whi
      le attempting to process a message inside a message-driven bean: com.bea.core.re
      packaged.springframework.beans.factory.BeanCreationException: Dependency injecti
      on failure: can't find the bean definition about class interface javax.sql.DataS
      ource; nested exception is com.bea.core.repackaged.springframework.beans.factory
      .NoSuchBeanDefinitionException: No unique bean of type [javax.sql.DataSource] is
       defined: No beans of type javax.sql.DataSource; owner=com.bea.core.repackaged.s
      pringframework.context.support.GenericApplicationContext@3de84b8: display name [
      com.bea.core.repackaged.springframework.context.support.GenericApplicationContex
      t@3de84b8]; startup date [Tue Jun 29 23:14:53 CDT 2010]; parent: com.bea.core.re
      packaged.springframework.context.support.GenericApplicationContext@3dd694f
      Nested exception: com.bea.core.repackaged.springframework.beans.factory.NoSuchBe
      anDefinitionException: No unique bean of type [javax.sql.DataSource] is defined:
       No beans of type javax.sql.DataSource; owner=com.bea.core.repackaged.springfram
      ework.context.support.GenericApplicationContext@3de84b8: display name [com.bea.c
      ore.repackaged.springframework.context.support.GenericApplicationContext@3de84b8
      ]; startup date [Tue Jun 29 23:14:53 CDT 2010]; parent: com.bea.core.repackaged.
      springframework.context.support.GenericApplicationContext@3dd694f
      Exception is : com.bea.core.repackaged.springframework.beans.factory.BeanCreatio
      nException: Dependency injection failure: can't find the bean definition about c
      lass interface javax.sql.DataSource; nested exception is com.bea.core.repackaged
      .springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of
      type [javax.sql.DataSource] is defined: No beans of type javax.sql.DataSource; o
      wner=com.bea.core.repackaged.springframework.context.support.GenericApplicationC
      ontext@3de84b8: display name [com.bea.core.repackaged.springframework.context.su
      pport.GenericApplicationContext@3de84b8]; startup date [Tue Jun 29 23:14:53 CDT
      2010]; parent: com.bea.core.repackaged.springframework.context.support.GenericAp
      plicationContext@3dd694f
              at com.bea.core.repackaged.springframework.jee.inject.Jsr250Metadata.app
      lyInjections(Jsr250Metadata.java:244)
              at com.bea.core.repackaged.springframework.jee.inject.Jsr250Metadata.inj
      ect(Jsr250Metadata.java:226)
              at com.bea.core.repackaged.springframework.jee.spi.EjbComponentCreatorBr
      okerImpl.injection(EjbComponentCreatorBrokerImpl.java:112)
              at com.bea.core.repackaged.springframework.jee.spi.EjbComponentCreatorBr
      okerImpl.getBean(EjbComponentCreatorBrokerImpl.java:70)
              at weblogic.ejb.container.injection.EjbComponentCreatorImpl.getBean(EjbC
      omponentCreatorImpl.java:68)
              at weblogic.ejb.container.manager.BaseEJBManager.createNewBeanInstance(B
      aseEJBManager.java:216)
              at weblogic.ejb.container.manager.BaseEJBManager.allocateBean(BaseEJBMan
      ager.java:231)
              at weblogic.ejb.container.manager.MessageDrivenManager.createBean(Messag
      eDrivenManager.java:288)
              at weblogic.ejb.container.pool.MessageDrivenPool.createBean(MessageDrive
      nPool.java:174)
              at weblogic.ejb.container.pool.MessageDrivenPool.getBean(MessageDrivenPo
      ol.java:99)
              at weblogic.ejb.container.internal.MDListener.execute(MDListener.java:43
      4)
              at weblogic.ejb.container.internal.MDListener.transactionalOnMessage(MDL
      istener.java:371)
              at weblogic.ejb.container.internal.NewJMSMessagePoller.processOneMessage
      (NewJMSMessagePoller.java:248)
              at weblogic.ejb.container.internal.NewJMSMessagePoller.run(NewJMSMessage
      Poller.java:121)
              at weblogic.ejb.container.internal.NewJMSMessagePoller.timerExpired(NewJ
      MSMessagePoller.java:208)
              at weblogic.timers.internal.TimerImpl.run(TimerImpl.java:273)
              at weblogic.work.SelfTuningWorkManagerImpl$WorkAdapterImpl.run(SelfTunin
      gWorkManagerImpl.java:528)
              at weblogic.work.ExecuteThread.execute(ExecuteThread.java:201)
              at weblogic.work.ExecuteThread.run(ExecuteThread.java:173)
      Caused by: com.bea.core.repackaged.springframework.beans.factory.NoSuchBeanDefin
      itionException: No unique bean of type [javax.sql.DataSource] is defined: No bea
      ns of type javax.sql.DataSource; owner=com.bea.core.repackaged.springframework.c
      ontext.support.GenericApplicationContext@3de84b8: display name [com.bea.core.rep
      ackaged.springframework.context.support.GenericApplicationContext@3de84b8]; star
      tup date [Tue Jun 29 23:14:53 CDT 2010]; parent: com.bea.core.repackaged.springf
      ramework.context.support.GenericApplicationContext@3dd694f
              at com.bea.core.repackaged.springframework.jee.inject.Jsr250Metadata.get
      UniqueInstanceOfType(Jsr250Metadata.java:305)
              at com.bea.core.repackaged.springframework.jee.inject.Jsr250Metadata.res
      olveByType(Jsr250Metadata.java:299)
              at com.bea.core.repackaged.springframework.jee.inject.Jsr250Metadata.res
      olve(Jsr250Metadata.java:286)
              at com.bea.core.repackaged.springframework.jee.inject.Jsr250Metadata.app
      lyInjections(Jsr250Metadata.java:238)
              at com.bea.core.repackaged.springframework.jee.inject.Jsr250Metadata.inj
      ect(Jsr250Metadata.java:227)
              at com.bea.core.repackaged.springframework.jee.spi.EjbComponentCreatorBr
      okerImpl.injection(EjbComponentCreatorBrokerImpl.java:112)
              at com.bea.core.repackaged.springframework.jee.spi.EjbComponentCreatorBr
      okerImpl.getBean(EjbComponentCreatorBrokerImpl.java:74)
              ... 15 more
      >
      <Jun 29, 2010 11:15:15 PM CDT> <Warning> <EJB> <BEA-010065> <MessageDrivenBean t
      hrew an Exception in onMessage(). The exception was:
       com.bea.core.repackaged.springframework.beans.factory.BeanCreationException: De
      pendency injection failure: can't find the bean definition about class interface
       javax.sql.DataSource; nested exception is com.bea.core.repackaged.springframewo
      rk.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [javax.sq
      l.DataSource] is defined: No beans of type javax.sql.DataSource; owner=com.bea.c
      ore.repackaged.springframework.context.support.GenericApplicationContext@3de84b8
      : display name [com.bea.core.repackaged.springframework.context.support.GenericA
      pplicationContext@3de84b8]; startup date [Tue Jun 29 23:14:53 CDT 2010]; parent:
       com.bea.core.repackaged.springframework.context.support.GenericApplicationConte
      xt@3dd694f.
      com.bea.core.repackaged.springframework.beans.factory.BeanCreationException: Dep
      endency injection failure: can't find the bean definition about class interface
      javax.sql.DataSource; nested exception is com.bea.core.repackaged.springframewor
      k.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [javax.sql
      .DataSource] is defined: No beans of type javax.sql.DataSource; owner=com.bea.co
      re.repackaged.springframework.context.support.GenericApplicationContext@3de84b8:
       display name [com.bea.core.repackaged.springframework.context.support.GenericAp
      plicationContext@3de84b8]; startup date [Tue Jun 29 23:14:53 CDT 2010]; parent:
      com.bea.core.repackaged.springframework.context.support.GenericApplicationContex
      t@3dd694f
              at com.bea.core.repackaged.springframework.jee.inject.Jsr250Metadata.app
      lyInjections(Jsr250Metadata.java:244)
              at com.bea.core.repackaged.springframework.jee.inject.Jsr250Metadata.inj
      ect(Jsr250Metadata.java:226)
              at com.bea.core.repackaged.springframework.jee.spi.EjbComponentCreatorBr
      okerImpl.injection(EjbComponentCreatorBrokerImpl.java:112)
              at com.bea.core.repackaged.springframework.jee.spi.EjbComponentCreatorBr
      okerImpl.getBean(EjbComponentCreatorBrokerImpl.java:70)
              at weblogic.ejb.container.injection.EjbComponentCreatorImpl.getBean(EjbC
      omponentCreatorImpl.java:68)
              Truncated. see log file for complete stacktrace
      

      以下是我在代码

      中连接数据库的方法
      // Datasource declaration
      @Resource(name = "database", mappedName = "datasource/oracle-11g")
      private DataSource database;
      ...
      // Save data to messages table
      String sql = "insert into messages(payload) values(?)";
      OracleConnection dbConn = (OracleConnection) database.getConnection();
      OraclePreparedStatement insertSql = (OraclePreparedStatement)   
      dbConn.prepareStatement(sql);
      insertSql.setStringForClob(1, msgPayload);
      insertSql.execute();
      

      到目前为止,我已完成以下问题排查:

      1. 我检查了我的数据源以确认jndi名称确实是“datasource / oracle-11g
      2. 我在数据源设置期间通过“测试配置”按钮成功连接到数据库
      3. 我已验证消息表确实存在于db
      4. 无论如何都要打开日志记录,以便我可以看到数据库中任何特定的JDBC连接错误?

3 个答案:

答案 0 :(得分:1)

您可能没有为weblogic管理控制台中定义的数据源设置目标管理服务器。 如果设置正确,则不应出现此错误。

答案 1 :(得分:0)

您的配置有问题。这是告诉你的信息:

Caused by: com.bea.core.repackaged.springframework.beans.factory.NoSuchBeanDefin
itionException: No unique bean of type [javax.sql.DataSource] is defined: No bea
ns of type javax.sql.DataSource

您要么没有DataSource,要么配置不正确。

答案 2 :(得分:0)

从发布的跟踪中,似乎MDB无法写入数据库,因为DataSource无法注入:

No unique bean of type [javax.sql.DataSource] is defined

某处发生了碰撞。我想你需要告诉我们更多更准确的答案。

更新:我想知道name@Resource属性(本例中为DataSource)使用相同的database是不是导致问题。

所以,而不是:

// Datasource declaration
@Resource(name = "database", mappedName = "datasource/oracle-11g")
private DataSource database;

你可以试试这个(假设datasource/oracle-11g是全局JNDI名称):

// Datasource declaration
@Resource(mappedName="datasource/oracle-11g") 
private DataSource database;

另见: