0
votes

My application is a servlet, spring 4 application where the spring jar is in the tomcat lib. Freemarker jar is in WEB-INF/lib.

I am getting this error when starting the server java.lang.ClassNotFoundException: freemarker.template.TemplateHashModelEx

This error disappears when I move the freemarker jar to tomcat lib directory.

It appears to me that spring 4 webmvc jar which contains Configurer class is unable to see WEB-INF/lib freemarker jar. I do not understand why freemarker jar in WEB-INF/lib folder is not visible to spring jar in tomcat lib folder.

What may I do to resolve this situation. My spring configuration is as follows

<bean id="freemarkerConfiguration" class="org.springframework.ui.freemarker.FreeMarkerConfigurationFactoryBean">
<!--Turn this off to always load via SpringTemplateLoader-->
    <property name="preferFileSystemAccess" value="false"></property>
    <property name="templateLoaderPath" value="classpath:/"></property>
</bean> 

<bean id="freemarkerConfigurer" class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
    <property name="configuration" ref="freemarkerConfiguration" />
</bean>
2
I've had similar issues before and what I did was to also right-click my project and configure build path and find and add as an external jar. If your not using Maven or another build-tool you should try this. - smoggers
I am using maven as my build tool. - Kamal Joshi
Anyone else has any ideas on how my spring context is broken when freemarker jar is in web-inf/lib and spring-web jar in tomcat/lib? - Kamal Joshi

2 Answers

1
votes

add the following code in pom.xml

<dependency>
    <groupId>org.freemarker</groupId>
    <artifactId>freemarker-gae</artifactId>
    <version>2.3.18</version>
</dependency>

This works for me.

0
votes

I've had similar issues before and I've solved it. Environment:Idea 、 Maven

  1. Open File->Project Structure->Artifacts
  2. Right click on the Project Library in the "Available Elements" to put in output root(WEB-INF/lib).
  3. Restart tomcat and you'll see the problem was solved.