可以根据JBoss 5.1中的JNDI条目做一个WAR吗? [英] Can I make a WAR depend on a JNDI entry in JBoss 5.1?
问题描述
作为从JBoss 4.0.4升级到5.1的一部分,我尝试在EAR成功部署后获得部署WAR。 JBoss 5.x不支持像4.x一样的 PrefixDeploymentSorter ,这意味着我必须使用< depend>在WAR的jboss-web.xml中。
似乎我不能依赖于EAR 本身,所以我选择最后部署的EJB。此EJB提供WAR需要的JNDI条目。
以下是在部署目录中缺少WAR时部署的EJB:
2010-03-25 10:47:30,348 INFO [org.jboss.ejb3.session.SessionSpecContainer](main)启动jboss.j2ee:ear = my- ear.ear,jar = mypackage-ejb.jar,name = MyFacadeBean,service = EJB3
2010-03-25 10:47:30,350 INFO [org.jboss.ejb3.EJBContainer](main)STARTED EJB:my .package.MyFacadeBean ejbName:MyFacadeBean
2010-03-25 10:47:30,371 INFO [org.jboss.ejb3.proxy.impl.jndiregistrar.JndiSessionRegistrarBase](main)绑定以下全局JNDI中的条目:
我/ MyFacade / local - EJB3.x默认本地业务接口
my-ear / MyFacadeBean / local-my.package.MyFacade - EJB3.x本地业务接口
这里是jboss-web.xml的依赖片段:
<取决于> jboss.j2ee:耳= MY-ear.ear,罐子= mypackage的-ejb.jar,姓名= MyFacadeBean ,服务= EJB3< /取决于>我的问题是:WAR开始在STARTED EJB:之后立即部署,即在MyFacadeBean之前是绑定到JNDI,这导致bean部署失败: 2010-03-25 10:47:39,068错误[my.facade FACadeFactory](main)MyFacade未绑定
2010-03-25 10:47:39,069错误[org.apache.catalina.core.ContainerBase。[jboss.web]。[my.host.no]。[ /]](main)StandardWrapper.Throwable
java.lang.ExceptionInInitializerError
java.lang.Class.forName0(Native Method)
java.lang.Class.forName(Class.java :164)
at my.freemarker.servlet.FreemarkerController.setupPojoServiceFactory(FreemarkerController.java:621)
[...]
导致:java.lang.RuntimeException:javax.naming。 NameNotFoundException:MyFacade没有绑定
在my.facade.FacadeFactory.getFacade(FacadeFactory.java:61)
在WAR完成部署之后,MyFacade快乐(嘲笑?)con将其部署并绑定到JNDI条目。
如果在EAR部署之后我部署了WAR,则一切都将按预期方式工作。
我甚至想到依赖于EAR中的虚拟EJB,并使用< module-order> strict< / module-order>在jboss-app.xml中强制它加载为最后一个模块。但唉, JBoss 5.x也不支持这一点。 Doh!
有没有办法依赖于JNDI条目?有没有其他方法来解决这个问题?
解决方案这是如何在JBoss 5.1.x上实现的。
首先,将一个名为 aliases.txt
的文件添加到 META-INF EAR目录。这个文件应该只包含一个带有您的EAR的任意名称/标识符的单行。例如,如果您有我的耳朵,您的 META-INF / aliases.txt
文件可能包含我的耳朵。它只需要一些不会与部署在同一台服务器上的其他应用程序声明的其他别名冲突的东西。
接下来,添加一个 jboss-dependency.xml
文件到您的WAR的 META-INF
目录,其中包含以下内容(为您的别名替换我的耳朵创建于上面):
< dependency xmlns =urn:jboss:dependency:1.0>
< item whenRequired =RealdependentState =Create> my-ear< / item>
< / dependency>
这将确保EAR在WAR之前部署。
此外,如果您尝试在没有EAR的情况下部署WAR,JBoss会记录一个清除的部署错误消息,告诉您有关缺少的依赖项。
As part of an upgrade from JBoss 4.0.4 to 5.1, I am trying to get a WAR to deploy after an EAR is successfully deployed. JBoss 5.x does not support PrefixDeploymentSorter like 4.x did, which means that I have to use <depends> in the WAR's jboss-web.xml.
It seems I cannot depend on the EAR itself, so I pick the last deployed EJB instead. This EJB provides a JNDI entry that the WAR needs.
Here's the EJB as it deploys when the WAR is absent from the deploy directory:
2010-03-25 10:47:30,348 INFO [org.jboss.ejb3.session.SessionSpecContainer] (main) Starting jboss.j2ee:ear=my-ear.ear,jar=mypackage-ejb.jar,name=MyFacadeBean,service=EJB3
2010-03-25 10:47:30,350 INFO [org.jboss.ejb3.EJBContainer] (main) STARTED EJB: my.package.MyFacadeBean ejbName: MyFacadeBean
2010-03-25 10:47:30,371 INFO [org.jboss.ejb3.proxy.impl.jndiregistrar.JndiSessionRegistrarBase] (main) Binding the following Entries in Global JNDI:
my/MyFacade/local - EJB3.x Default Local Business Interface
my-ear/MyFacadeBean/local-my.package.MyFacade - EJB3.x Local Business Interface
And here's the depends snippet from jboss-web.xml:
<depends>jboss.j2ee:ear=my-ear.ear,jar=mypackage-ejb.jar,name=MyFacadeBean,service=EJB3</depends>
My problem is: The WAR starts to deploy immediately after "STARTED EJB:", i.e. before MyFacadeBean is bound to JNDI, which causes bean deployments to fail:
2010-03-25 10:47:39,068 ERROR [my.facade.FacadeFactory] (main) MyFacade not bound
2010-03-25 10:47:39,069 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[my.host.no].[/]] (main) StandardWrapper.Throwable
java.lang.ExceptionInInitializerError
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:164)
at my.freemarker.servlet.FreemarkerController.setupPojoServiceFactory(FreemarkerController.java:621)
[...]
Caused by: java.lang.RuntimeException: javax.naming.NameNotFoundException: MyFacade not bound
at my.facade.FacadeFactory.getFacade(FacadeFactory.java:61)
After the WAR has finished its deployment, MyFacade happily (mockingly?) continues its deployment and binds the JNDI entries.
If I hot-deploy the WAR after the EAR has deployed, everything works as intended.
I even thought of depending on a dummy EJB in the EAR, and using <module-order>strict</module-order> in jboss-app.xml to force it to load as the last module. But alas, JBoss 5.x does not support that either. Doh!
Is there a way to depend on the JNDI entry itself? Are there other ways of solving this?
解决方案 Here's how you can achieve this on JBoss 5.1.x.
First, add a file called aliases.txt
into the META-INF
directory of your EAR. This file should just contain a single line with an arbitrary name / identifier for your EAR. For example, if you have my-ear.ear, your META-INF/aliases.txt
file could contain 'my-ear'. It just needs to be something that won't clash with any other aliases declared by other apps deployed on the same server.
Next, add a jboss-dependency.xml
file to the META-INF
directory of your WAR, containing the following (subsituting 'my-ear' for the alias you created above):
<dependency xmlns="urn:jboss:dependency:1.0">
<item whenRequired="Real" dependentState="Create">my-ear</item>
</dependency>
This will ensure the EAR is deployed before the WAR.
Also, if you try to deploy the WAR without the EAR being present, JBoss will log a clear deployment error message telling you about the missing dependency.
这篇关于可以根据JBoss 5.1中的JNDI条目做一个WAR吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!