@EJB从不同的罐子注入 [英] @EJB inject from different jar
问题描述
如果我使用正常注入
@EJB
IBean injectBean;
或
@EJB
IBeanLocal injectBean;
部署应用程序时,我得到一个NullPointerException。
如果我使用:
@EJB(mappedName =Bean)
IBean injectBean;
或
@EJB(mappedName =Bean)
IBeanLocal injectBean;
一切正常,JBoss不会发生部署错误。
我可能会提到我使用JBoss 5。
我注入的bean类被声明为:
@Remote
public interface IBean
@Local
public interface IBeanLocal扩展IBean
@Stateless name =Bean)
public class Bean实现IBean,IBeanLocal
我的问题是如文档中指定的mappedName属性是供应商特定的。有没有其他方式我可以让这个工作?
解决方案:
问题是我试图单独部署两个jar,这意味着每个jar都将在JBoss中获得它自己的ClassLoader,以便他们找不到并返回NullPointerException当尝试注入bean时。
解决方案是将jar添加到一个耳朵,并添加一个包含application.xml的META-INF,如下所示: p>
< application xmlns =http://java.sun.com/xml/ns/j2ee
xmlns: xsi =http://www.w3.org/2001/XMLSchema-instance
xsi:schemaLocation =http://java.sun.com/xml/ns/j2ee
http:/ /java.sun.com/xml/ns/j2ee/application_1_4.xsd
version =1.4>
< display-name>应用程序的简单示例< / display-name>
< module>
< ejb> ejb1.jar< / ejb>
< / module>
< module>
< ejb> ejb2.jar< / ejb>
< / module>
< / application>
我还必须更改一些JNDI查找,以便通过添加耳机名称来匹配新结构这些类:ear-name / bean
此后,我只是将jar添加到耳朵,所有部署都很好。
尝试用 @EJB(beanName =Bean)注入你的bean
不知道是否可以正常工作,但是我们也有类似的问题,这是由于缺少 beanName
属性导致的。
I'm trying to inject a bean located in a different jar file then the bean i'm trying to inject it into. Both beans are just basic @Stateless beans with local and remote interfaces. If i use the normal injection
@EJB
IBean injectedBean;
or
@EJB
IBeanLocal injectedBean;
i get a NullPointerException when deploying the application.
If i use:
@EJB(mappedName="Bean")
IBean injectedBean;
or
@EJB(mappedName="Bean")
IBeanLocal injectedBean;
everything works and JBoss throws no deployment errors.
I might mention i use JBoss 5.
The bean class i'm injecting is declared as:
@Remote
public interface IBean
@Local
public interface IBeanLocal extends IBean
@Stateless(name = "Bean")
public class Bean implements IBean, IBeanLocal
My problem is that as specified in the documentation the mappedName property is vendor-specific. Is there any other way i could get this to work?
SOLVED:
I managed to solve the problem.
The problem was that i tried to deploy both jars individually which meant that each would get it's own ClassLoader in JBoss so that they couldn't find each other and would return a NullPointerException when trying to inject the bean.
The sollution was to add the jars to an ear and add an META-INF containing an application.xml looking like this:
<application xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/application_1_4.xsd"
version="1.4">
<display-name>Simple example of application</display-name>
<module>
<ejb>ejb1.jar</ejb>
</module>
<module>
<ejb>ejb2.jar</ejb>
</module>
</application>
I also had to change some JNDI lookups i made to match the new structure by adding the ear name before the classes: "ear-name/bean"
After this i just added the jars to the ear and everything deployed nicely.
Try injecting your bean with @EJB(beanName = "Bean")
Not sure if it'll work, but we had a similar issue and it was caused by the lack of the beanName
attribute.
这篇关于@EJB从不同的罐子注入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!