If you just want to get the value of the variable that was defined in the context of the container and use it as a string without creating a placeholder object, you can do the following (this has been tested in Tomcat, but most likely works the same in other containers / JEE- servers such as WebSphere):
Define the environment variable in Tomcat context.xml (or use your own server syntax):
<Environment type="java.lang.String" name="myString" value="hello"/>
In the Spring XML text file:
Add the jee namespace to the root element:
xmlns:jee="http://www.springframework.org/schema/jee"
and in xsi:schemaLocation :
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd
Now you can easily find the value (note that you do not need to specify java:/comp/env material java:/comp/env , Spring does this for you):
<jee:jndi-lookup id="myStringValue" jndi-name="myStringValue" expected-type="java.lang.String" />
Then you can use it, for example, pass it to the bean constructor as a reference:
<bean id="observationFileManager" class="my.service.Bean"> <constructor-arg name="myString" ref="myStringValue" /> </bean>
bean will get "hello" as its arg constructor.
EDIT:
If you run your Spring context outside the container (Tomcat, Websphere ...) to test integration, the search will not work. Therefore, if you have a special test context, simply add the following String definition that will override jee:lookup and set the value that you want to use for testing:
<bean id="mediaFilesBaseDirPath" class="java.lang.String" > <constructor-arg value="Z:" /> </bean>