Where does java:comp/env point to?

Viewed 1193

I see this in the application-context.xml of my Spring-Boot project :

<bean id="configurationPath" class="org.springframework.jndi.JndiObjectFactoryBean">
        <property name="jndiName">
            <value>java:comp/env/application.properties</value>
        </property>
    </bean>

I want to know where does java:comp/env point to ?

1 Answers

The java:comp/env instruction represents the root node in the JNDI tree where you can find properties for the current Java EE component (in this case the properties file). Every application server / servlet container implements it in different ways. You should check the official documentation of your application server or servlet container. I'm not expert of spring boot but since it usually starts with an embedded tomcat, it should be the default location in tomcat servlet cointainer Moreover in tomcat servlet container you can define it by using the <Environment> tag of the context.xml file

For example if in your context.xml file you put:

<Environment name="myPropertiesFilesLocation" value="${catalina.home}/properties" type="java.lang.String" override="false" />

When you make a JNDI search like this one java:comp/env/myPropertiesFilesLocation will point to ${catalina.home}/properties

Related