参考这个问题和这个URL(两者都在下面给出),我有完全相同的要求,但在ejb-jar.xml中,我知道我必须插入这部分
<resource-env-ref>
<resource-env-ref-name>MyConstants</resource-env-ref-name>
<resource-env-ref-type>com.ibm.acme.ree.lib.Config</resource-env-ref-type>
</resource-env-ref>
但是这部分不能直接插入“ejb-jar”的标签内,它必须在“企业bean”或“汇编描述符”或“关系”等子标签内,请帮我准确xml代码。
How to reference a websphere Resource Environment Provider in web.xml?
http://www.ibm.com/developerworks/websphere/library/techarticles/0611_totapally/0611_totapally.html
答案 0 :(得分:0)
这样的事情可以作为一个起点:
<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar
xmlns="http://java.sun.com/xml/ns/javaee"
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"
version="3.0"
>
<enterprise-beans>
<session>
<ejb-name>TestBean</ejb-name>
<session-type>Stateless</session-type>
<resource-env-ref>
<resource-env-ref-name>MyConstants</resource-env-ref-name>
<resource-env-ref-type>com.ibm.acme.ree.lib.Config</resource-env-ref-type>
</resource-env-ref>
</session>
</enterprise-beans>
</ejb-jar>
我省略了其他必需元素,例如<ejb-class>
和<session-type>
,除非您使用注释,否则这些元素是必需的。好吧,如果你正在使用注释,那么使用@Resource
要比<resource-env-ref>
容易得多:
@Stateless
public class TestBean {
@Resource
private Config config;
...
}