【发布时间】:2013-04-10 21:17:09
【问题描述】:
我有一个依赖于 EJB 项目的 Maven Web 应用程序。
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>soar-ejb</artifactId>
<version>1.0</version>
<type>jar</type>
</dependency>
在 EJB 项目中,我在 ejb-jar.xml 中添加了一个 env-entry,如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar xmlns = "http://java.sun.com/xml/ns/javaee"
version = "3.1"
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_1.xsd">
<enterprise-beans>
<session>
<env-entry>
<description>Config file</description>
<env-entry-name>configFileLocation</env-entry-name>
<env-entry-type>java.lang.String</env-entry-type>
<env-entry-value>dropbox-config.properties</env-entry-value>
</env-entry>
</session>
</enterprise-beans>
</ejb-jar>
我已经使用 arquillian 测试了 EJB 项目,我可以使用 @Resource 注入这个值
因此:
@Resource(name = "configFileLocation")
私有字符串配置文件;
现在,当我使用 ejb 依赖项构建 .war 时,我会在 WEB-INF\lib 中获得一个包含我的 EJB 项目的 .war 作为 .jar 文件。在这个 EJB 项目中(即 .jar 中),ejb-jar.xml 文件位于正确的 META-INF 目录中。
但是现在,当我部署到服务器时,@Resource 注入永远不会起作用。 String 始终为 null。根据我所读到的,我在 EJB 项目和 .war 生成的 .war 中都有正确的位置 ejb-jar.xml 。
有人知道我的配置不正确吗?
谢谢!
编辑:
将会话元素修改为
<session>
<description>An EJB that loads configuration from a file</description>
<display-name>ConfigurationProducer</display-name>
<ejb-name>ConfigurationProducer</ejb-name>
<ejb-class>com.trf.util.DropboxConfigFileProducer</ejb-class>
<session-type>Stateless</session-type>
<env-entry>
<description>Location of the config file</description>
<env-entry-name>configFileLocation</env-entry-name>
<env-entry-type>java.lang.String</env-entry-type>
<env-entry-value>dropbox-config.properties</env-entry-value>
</env-entry>
</session>
【问题讨论】:
标签: jakarta-ee maven-2 glassfish-3 ejb-3.1 ejb-jar.xml