2

I tried to integrate Freemarker templates to Spring mvc application. I tried it as shows in tutorials.Here is the code, I am using freemarker 2.3.15

servletcontext.xml

 <!-- freemarker config -->
    <beans:bean id="freemarkerConfig" class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
      <beans:property name="templateLoaderPath" value="/WEB-INF/views/"/>
    </beans:bean>

    <!--
      View resolvers can also be configured with ResourceBundles or XML files. If you need
      different view resolving based on Locale, you have to use the resource bundle resolver.
    -->
    <beans:bean id="viewResolver" class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">
      <beans:property name="cache" value="true"/>
      <beans:property name="prefix" value="/WEB-INF/views/"/>
      <beans:property name="suffix" value=".ftl"/>
    </beans:bean>

It gives to errors:

1. Build path is incomplete. Cannot find class file for org/springframework/ui/freemarker/
 FreeMarkerConfigurationFactory

2.No setter found for property 'templateLoaderPath' in class 
 'org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer' [config set: Warehouse/web-context]
rohi
  • 320
  • 1
  • 5
  • 20
  • How are you building the application? Looks like the first is a dependency issue, but the reason varies depending on how you have it set up (Maven, Ant, etc). Not sure on the second one yet. Whatever other details you can post would be helpful. – Mark Madej Nov 12 '14 at 04:46
  • Possible duplicate of [ClassNotFoundException FreeMarkerConfigurationFactory](http://stackoverflow.com/questions/18127703/classnotfoundexception-freemarkerconfigurationfactory) – naXa stands with Ukraine Jan 27 '17 at 11:19

2 Answers2

10

Add the spring-context-support dependency to your project.

In pom.xml,

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context-support</artifactId>
    <version>3.2.4.RELEASE</version>
</dependency>

Reference: ClassNotFoundException with Freemarker

and

Spring Freemarker Configuration, Template Not Found

Community
  • 1
  • 1
spiderman
  • 10,892
  • 12
  • 50
  • 84
0

I'm here years later, having encountered this problem. None of the solutions I found on the web work. I don't know if the FreeMarker or Spring libraries changed or what. I finally struck upon a solution that work, kind of.

I had the following code:

@Autowired
private FreeMarkerConfigurationFactoryBean freeMarkerConfigFactory;

When including this jar in another project, that project could suddenly no longer resolve this dependency. The new project I'm working on doesn't actually need FreeMarker, but I needed to get Spring to resolve the dependency so that my program would run.

I commented out the two lines above, and instead added the following:

private FreeMarkerConfigurationFactoryBean freeMarkerConfigFactory = new FreeMarkerConfigurationFactoryBean();

This allows my program to run because Spring doesn't need to autowire this bean.

Why it stopped working after years of working, I don't know. Also, I didn't test the above code because, again, I don't need FreeMarker. I just needed the autowiring to work.

Maybe this will help someone else (or help me when I come looking for this solution again in five years. Because I already solved this once, but didn't document it in a readme file. I had to find my comments in the code.)

Marvo
  • 17,845
  • 8
  • 50
  • 74