문제

I have a maven web application that has a dependency on an EJB project.

   <dependency>
        <groupId>${project.groupId}</groupId>
        <artifactId>soar-ejb</artifactId>
        <version>1.0</version>
        <type>jar</type>
    </dependency>

In the EJB project there I've added an env-entry in the ejb-jar.xml as such:

<?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>

I've tested the EJB project, using arquillian, and I am able to inject this value using @Resource as such: @Resource(name = "configFileLocation") private String configFile;

Now, when I build the .war with the ejb dependency, I get a .war with my EJB project as a .jar inside WEB-INF\lib. Within this EJB project (i.e. inside the .jar) the ejb-jar.xml file is in the proper META-INF directory.

BUT now, when I deploy to the server the @Resource injection never works. The String is always null. According to what I have read I have the ejb-jar.xml in the correct location, both within the EJB project and within the .war that maven produces.

Would someone have an idea of what I've configured incorrectly?

Thanks!

EDIT:

Modified the session element to

<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>
도움이 되었습니까?

해결책

I solved this by modifying the dependency for the ejb project in pom.xml to be provided and then wrapping the war and ejb projects into an ear project. pom.xml of the web archive now looks like this:

    <dependency>
        <groupId>${project.groupId}</groupId>
        <artifactId>soar-ejb</artifactId>
        <version>1.0</version>
        <scope>provided</scope>
    </dependency>

Then in the ear project's pom.xml we have this:

 <dependencies>
    <dependency>
        <groupId>${project.groupId}</groupId>
        <artifactId>soar-ejb</artifactId>
        <version>1.0</version>
        <type>ejb</type>
    </dependency>
    <dependency>
        <groupId>${project.groupId}</groupId>
        <artifactId>soar-war</artifactId>
        <version>1.0</version>
        <type>war</type>
    </dependency>
</dependencies>

@Resource injection is now working on the env-entries in the ejb's ejb-jar.xml when I deploy to the server from the ear project !

다른 팁

The session element of your ejb-jar.xml doesn't contain the ejb-name property, try to put one with the name matching the bean interface name. I've edited your answer to show you an example.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top