mikeb
mikeb

Reputation: 11265

Spring Context configuration that needs the ServletContext passed to constructor

I'm configuring a bean in a spring webapp context that needs the ServletContext passed into the constructor:

WebappTemplateLoader(javax.servlet.ServletContext servletContext)

Here is my bean definition in the xml configuration file:

<bean id="ftlTemplateLoader" class="freemarker.cache.WebappTemplateLoader">
    <constructor-arg>
    </constructor-arg>
</bean>

What do I put in for the constructor arg so that this bean gets a proper ServletContext?

Edit:

Turns out the answer is:

<bean id="ftlTemplateLoader" class="freemarker.cache.WebappTemplateLoader">
    <constructor-arg value="#{servletContext}">
    </constructor-arg>
</bean>

Upvotes: 1

Views: 587

Answers (1)

Sotirios Delimanolis
Sotirios Delimanolis

Reputation: 279890

You should be able to use

<bean id="ftlTemplateLoader" class="freemarker.cache.WebappTemplateLoader">
    <constructor-arg value="#{servletContext}">
    </constructor-arg>
</bean>

assuming your XML file is being loaded in the context of a WebApplicationContext.

Upvotes: 1

Related Questions