优快云论坛上看见好几个人都在问关于李腾飞版EJB3.0讲座中的MDB例子,为什么在他们的JBoss版本下跑不通,主要是“jms not bound” 这个问题。
有一些“高手”给出了一个方案,在/deploy/目录下放置一个 xxx-server.xml 的配置文件,内容是:
<?xml version="1.0" encoding="UTF-8" ?> <server> <mbean code="org.jboss.mq.server.jmx.Queue" name="jboss.org.destination:server=Queue,name=accpQueue" > <attribute name="JNDIName" >queue/accpQueue </attribute> <depends optional-attribute-name = "DestinationManager" > jboss.mq:service=DestinationManager </depends> </mbean> </server>
这样就把“queue/accpQueue” 这样一个queue资源配置好了,MDB的注解destination属性值设为这个就可以。
这个法子虽然管用,但用来回答问题显然容易把人引入误区,以为非要这个配置文件不可。实际上这个配置文件是不需要的,问题是出在自定义的JNDI名字上。参考JBoss的文档页(http://www.jboss.ru/docs/JBoss-2001-06-28/ch07s07.html)我们看到一句话:
“In the bean part one always have to specify the JNDI for the JMS destination. In JBossMQ this always begins with either "topic/" or "queue/" followed by the name of the destination.”
原来如此,李腾飞在教学视频里写的例子,jms destination 的JNDI写的是 "jms/xxxx" ,但是比视频里更新版本的JBoss显然不再承认这种写法,这里只要在annotation里把 "jms/" 改成 "queue/" 就行了,根本无需额外的XML配置文件。