Weblogic找不到具有“正确” JNDI名称的资源适配器进行绑定

Yun*_*Yun 5 ejb weblogic jndi adapter jca

我试图将消息驱动的Bean与Weblogic 10.3.5上的Oracle JCA文件适配器(包含在SOA套件中)绑定。这样,当任何.txt文件移动到特定目录时,我的MDB都可以得到通知。

启动支持SOA功能的Weblogic域后,将自动部署文件适配器。在Weblogic控制台上,我可以看到文件适配器已部署为“资源适配器”,运行状况为“确定”,状态为“活动”,如下所示:

Weblogic中已部署的文件适配器

我也运行了文件适配器的测试,并且都通过了:

在此处输入图片说明

因此,我认为文件适配器已正确部署并且应该可以正常工作。

然后我的消息驱动bean代码如下所示:

import java.util.logging.Logger;
import javax.ejb.MessageDriven;
import javax.resource.ResourceException;
import javax.resource.cci.MessageListener;
import javax.resource.cci.Record;

@MessageDriven
public class FileAdapterClientMDB implements MessageListener {

    private Logger logger = Logger.getLogger(FileAdapterClientMDB.class.getName());

    public FileAdapterClientMDB() {

    }

    @Override
    public Record onMessage(Record record) throws ResourceException {
        logger.info("Received record: " + record);
        return record;
    }
}
Run Code Online (Sandbox Code Playgroud)

这是我的ejb-jar.xml文件的内容:

<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:ejb="http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd" version="3.0">
  <display-name>MockEJB</display-name>
  <enterprise-beans>
    <message-driven>
      <description>EMessage Driven Bean as File Adapter Client</description>
      <display-name>FileAdapterClientMDB</display-name>
      <ejb-name>FileAdapterClientMDB</ejb-name>
      <ejb-class>com.test.FileAdapterClientMDB</ejb-class>
      <messaging-type>javax.resource.cci.MessageListener</messaging-type>
      <transaction-type>Container</transaction-type>
      <activation-config>
        <activation-config-property>
          <activation-config-property-name>physicalDirectory</activation-config-property-name>
          <activation-config-property-value>C:\dataDir</activation-config-property-value>
        </activation-config-property>
        <activation-config-property>
          <activation-config-property-name>deleteFile</activation-config-property-name>
          <activation-config-property-value>true</activation-config-property-value>
        </activation-config-property>
        <activation-config-property>
          <activation-config-property-name>pollingFrequency</activation-config-property-name>
          <activation-config-property-value>10</activation-config-property-value>
        </activation-config-property>
        <activation-config-property>
          <activation-config-property-name>includeFiles</activation-config-property-name>
          <activation-config-property-value>.*\.txt</activation-config-property-value>
        </activation-config-property>
        <activation-config-property>
          <activation-config-property-name>minimumAge</activation-config-property-name>
          <activation-config-property-value>0</activation-config-property-value>
        </activation-config-property>
      </activation-config>
    </message-driven>
  </enterprise-beans>
</ejb-jar>
Run Code Online (Sandbox Code Playgroud)

还有我的weblogic-ejb-jar.xml文件:

<?xml version="1.0" encoding="UTF-8"?>
<wls:weblogic-ejb-jar xmlns:wls="http://www.bea.com/ns/weblogic/weblogic-ejb-jar" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd http://www.bea.com/ns/weblogic/weblogic-ejb-jar http://www.bea.com/ns/weblogic/weblogic-ejb-jar/1.0/weblogic-ejb-jar.xsd">
    <!--weblogic-version:10.3-->
    <wls:weblogic-enterprise-bean>
        <!--options:RESOURCE_ADAPTER_JNDI-->
        <wls:ejb-name>FileAdapterClientMDB</wls:ejb-name>
        <wls:message-driven-descriptor>
            <wls:resource-adapter-jndi-name>eis/FileAdapter</wls:resource-adapter-jndi-name>
        </wls:message-driven-descriptor>
        <wls:jndi-name>FileAdapterClientMDB</wls:jndi-name>
        <wls:local-jndi-name>FileAdapterClientMDB</wls:local-jndi-name>
    </wls:weblogic-enterprise-bean>
</wls:weblogic-ejb-jar>
Run Code Online (Sandbox Code Playgroud)

在部署EAR项目时,我收到以下消息:

<20.4.2012 22:42:11 CEST> <Warning> <EJB> <BEA-010221> <The Message-Driven EJB: 
FileAdapterClientMDB is unable to bind to the JCA resource adapter: eis/FileAdapter. 
The Error was: No deployed ResourceAdapter with adapter JNDI name = 'eis/FileAdapter' was found.>
Run Code Online (Sandbox Code Playgroud)

我不知道为什么Weblogic会抱怨这一点,因为在适配器的官方用户指南中提到了“ eis / FileAdapter” JNDI名称。我也可以在Weblogic的JNDI树中看到它:

在此处输入图片说明

而且,当我在测试Web服务中运行以下代码时:

try {
    final Context context = new InitialContext();
    final Object obj = context.lookup("eis/FileAdapter");
    System.out.println("eis/FileAdapter => " + obj);
} catch (NamingException e) {
    e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)

它输出“ eis / FileAdapter => oracle.tip.adapter.file.FileConnectionFactory@ff51dc ”,这意味着JNDI名称正确!

所以我的问题是,为什么Weblogic找不到具有“正确” JNDI名称的资源适配器进行绑定? 有人可以给我一些解决方法的想法吗?

小智 0

只要您没有重复看到此警告,就无需担心。它只是表明,按照部署顺序,当部署 MDB 时,它无法获取适配器。请注意,MDB 会每 5 秒尝试连接一次,因此如果警告继续填满日志,则意味着 MDB 无法获取适配器,这意味着它无法工作,如果您只看到警告一次,则可以安全地忽略它或更改部署顺序并稍后推送 MDB。