views:

284

answers:

1

Greetings,

Is there any Spring variable for Web application folder? I want to assign a bean property as following.

Where ${WEBAPP-FOLDER} is the absolute path of the web-app folder.

Any tips?

<bean id="compass" class="org.compass.spring.LocalCompassBean">
            .
                .
                <prop key="compass.engine.connection">file:///${WEBAPP-FOLDER}/WEB-INF/searchIndex</prop>       
</bean>
+2  A: 

No, but you can obtain it through a ServletContextListener, by calling

event.getServletContext.getRealPath("/")

You can now set it in a static variable (which will logically be a constant), or get the spring application context and set it manually (via WebApplicationUtils) in the bean.

Bozho
Thanks Bozho ,so if I set it in a static variable (say public static String WEBAPPFOLDER) in Listener , how can spring access it ? just $WEBAPPFOLDER ?
umanga
well, not spring - you will access it directly `MyStaticHolder.WEBAPPFOLDER` - it won't be known to spring, just known to you.
Bozho