Announcement Announcement Module
Collapse
No announcement yet.
FreeMarker configuration troubles Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • FreeMarker configuration troubles

    Am I missing something here?

    I'm trying to configure FreeMarker (non web environment). I have the following in a context file:

    Code:
    <bean 
      id="freeMarkerConfig"
      class="org.springframework.ui.freemarker.FreeMarkerConfigurationFactoryBean">
      <property name="templateLoaderPath"><value>classpath&#58;/my/package/name/freemarker/</value></property>
    </bean>
    Where
    * "/my/pacakge/name/freemarker/" is the directory (on the classpath) that I keep my FreeMarker template files.


    In my calling code, I have:
    Code:
    Template t = freeMarkerConfig.getTemplate&#40;"simpleTemplate.ftl"&#41;;
    And I get the following error:

    Code:
    java.io.FileNotFoundException&#58; Template simpleTemplate.ftl not found.
    	at freemarker.template.Configuration.getTemplate&#40;Configuration.java&#58;428&#41;
    	at freemarker.template.Configuration.getTemplate&#40;Configuration.java&#58;391&#41;
    	at dars.apis.audit.view.format.freemarker.FreeMarkerAuditFormatter.format&#40;FreeMarkerAuditFormatter.java&#58;45&#41;
    	at dars.apis.audit.view.format.AbstractAuditFormatterTest.testSanityPrint&#40;AbstractAuditFormatterTest.java&#58;41&#41;
    	at sun.reflect.NativeMethodAccessorImpl.invoke0&#40;Native Method&#41;
    	at sun.reflect.NativeMethodAccessorImpl.invoke&#40;Unknown Source&#41;
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke&#40;Unknown Source&#41;
    	at java.lang.reflect.Method.invoke&#40;Unknown Source&#41;
    	at junit.framework.TestCase.runTest&#40;TestCase.java&#58;154&#41;
    	at junit.framework.TestCase.runBare&#40;TestCase.java&#58;127&#41;
    	at junit.framework.TestResult$1.protect&#40;TestResult.java&#58;106&#41;
    	at junit.framework.TestResult.runProtected&#40;TestResult.java&#58;124&#41;
    	at junit.framework.TestResult.run&#40;TestResult.java&#58;109&#41;
    	at junit.framework.TestCase.run&#40;TestCase.java&#58;118&#41;
    	at junit.framework.TestSuite.runTest&#40;TestSuite.java&#58;208&#41;
    	at junit.framework.TestSuite.run&#40;TestSuite.java&#58;203&#41;
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests&#40;RemoteTestRunner.java&#58;421&#41;
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run&#40;RemoteTestRunner.java&#58;305&#41;
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main&#40;RemoteTestRunner.java&#58;186&#41;
    I know it's got to be at least semi-obvious - does anyone see what I'm doing wrong here?

    Thanks
    Jon

  • #2
    do you have any messages in your logs during bean creation that start with "Cannot resolve template loader path.."? You'll need logging set to at least INFO for the org.springframework.ui.freemarker package to see it.

    Also, is your template directory an expanded classpath or in a JAR file somewhere?

    Regards,

    Comment


    • #3
      Darren,

      I've got logging turned up, and unfortunately, no such message appears.

      I started stepping through FreeMarker's template loading in the debugger, however, and I see it's trying to use its FileTemplateLoader to load the template - it's not surprising that doesn't work, as I have multiple source directories and it looks like it's being forced to choose just one.

      I think the solution is to set the TemplateLoader FreeMarker is using to ClassTemplateLoader. Unfortunately, I've been unable to figure out how to do so in a context file.

      Any help with that?

      Thanks,
      Jon

      Comment

      Working...
      X