Frage

I am tying to inject an file directory string using @resource , the declaration of this string is in the application.xml file, here is my code

<application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:application="http://java.sun.com/xml/ns/javaee/application_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_6.xsd"
id="Application_ID" version="6">

<display-name>Project_APP</display-name>

<module>
    <ejb>Project_Dalayer.jar</ejb>
</module>
<module>
    <web>
        <web-uri>Project_UI.war</web-uri>
        <context-root>Project_UI</context-root>
    </web>
</module>

<env-entry>
    <env-entry-name>java:app/env/logDirName</env-entry-name>
    <env-entry-type>java.lang.String</env-entry-type>
    <env-entry-value>/app/Project_Data/logs/</env-entry-value>
</env-entry>

The class in the dal layer

@Startup
@Singleton
public class LoggingManager{
    @Resource(name = "java:app/env/logDirName")
     private String logDirName;
}

This string logDirName returns null.

War es hilfreich?

Lösung

EJB 3.1 has (finally) standarized the global JNDI entries and your EJB code looks fine, what is failing , I think, is the config on your application.xml. Your env entry should look like this:

<env-entry>
    <env-entry-name>logDirName</env-entry-name>
    <env-entry-type>java.lang.String</env-entry-type>
    <env-entry-value>/app/Project_Data/logs/</env-entry-value>
</env-entry>

i.e. the container will set you entry under java:app/env/ by you.

Cheers

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top