【发布时间】:2012-04-20 21:25:50
【问题描述】:
我正在尝试将我的消息驱动 bean 与 Weblogic 10.3.5 上的 Oracle JCA 文件适配器(包含在 SOA 套件中)绑定。这样当有任何 .txt 文件移动到特定目录时,我的 MDB 可以得到通知。
启动支持 SOA 功能的 Weblogic 域后,文件适配器会自动部署。在Weblogic控制台上我可以看到文件适配器部署为“资源适配器”,健康为“OK”,状态为“Active”,如下图:
我还运行了文件适配器的测试,它们都通过了:
所以我认为文件适配器已正确部署并且应该可以正常工作。
那么我的消息驱动 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;
}
}
这是我的 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>
还有我的 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>
在部署 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.>
我不知道为什么 Weblogic 会抱怨这个,因为官方 user guide of the adapter 中提到了“eis/FileAdapter”JNDI 名称。我也可以在 Weblogic 的 JNDI 树中看到它:
更重要的是,当我在我的测试网络服务中运行以下代码时:
try {
final Context context = new InitialContext();
final Object obj = context.lookup("eis/FileAdapter");
System.out.println("eis/FileAdapter => " + obj);
} catch (NamingException e) {
e.printStackTrace();
}
打印出“eis/FileAdapter => oracle.tip.adapter.file.FileConnectionFactory@ff51dc”,表示JNDI名称正确!
所以我的问题是,为什么 Weblogic 找不到用于绑定的“正确”JNDI 名称的资源适配器?有人能给我一些解决方法的想法吗?
【问题讨论】:
-
Nitpick:您是否尝试将您的
weblogic-ejb-jar.xml的标签值更改为eis.FileAdapter?
标签: ejb weblogic adapter jndi jca