title: Spring Jndi Context and PropertyPlaceholderConfigurer
body: <p>Using Spring, I want to read a variable inside the context of Webspehere.</p>
  
  <p><a href="https://stackoverflow.com/questions/6979958/read-a-environment-variable-in-java-with-websphere/">Read a Environment Variable in Java with Websphere</a></p>
  
  <p>To define the data.... inside web.xml</p>
  
  <pre><code>&lt;env-entry&gt;
     &lt;env-entry-name&gt;varName&lt;/env-entry-name&gt;
     &lt;env-entry-value&gt;56&lt;/env-entry-value&gt;
     &lt;env-entry-type&gt;java.lang.String&lt;/env-entry-type&gt;
  &lt;/env-entry&gt;
  </code></pre>
  
  <p>To see with java</p>
  
  <pre><code>Context envEntryContext = (Context) new InitialContext().lookup("java:comp/env");
  String mydata = (String)envEntryContext.lookup(“varName”);
  </code></pre>
  
  <p>But I want take the data in my common.xml like</p>
  
  <pre><code>&lt;bean id="propertyPlaceholderConfigurer"
      class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"&gt;
      &lt;property name="locations"&gt;
          &lt;list&gt;
              &lt;value&gt;/WEB-INF/context/servweb.properties&lt;/value&gt;
          &lt;/list&gt;
      &lt;/property&gt;
      &lt;property name="ignoreUnresolvablePlaceholders"&gt;
          &lt;value&gt;true&lt;/value&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>maybe with something like that</p>
  
  <pre><code> &lt;constructor-arg&gt;
       &lt;jee:jndi-lookup jndi-name="java:comp/env" default-value="data" /&gt; 
    &lt;/constructor-arg&gt;
  </code></pre>
  
  <p>but with context for do the same that</p>
  
  <pre><code>Context envEntryContext = (Context) new InitialContext().lookup("java:comp/env");
  String mydata = (String)envEntryContext.lookup(“varName”);
  </code></pre>
  
  <p>maybe something like that:</p>
  
  <pre><code> &lt;constructor-arg&gt;
      &lt;jee:jndi-lookup  jndi-name="java:comp/env"&gt;
        &lt;jee:environment&gt;
            varName=default
       &lt;/jee:environment&gt;
    &lt;/jee:jndi-lookup&gt;
  </code></pre>
  
  <p>Anybody knows the correct way?</p>
  
  <p>Thanks in Advance</p>