0
votes

I'm having an issue with my view resolver not being able to find my appropriate freemarker template.

Is there a way to tell the resolver bean and/or spring to output the file path it is looking for?

ie if my controller returns a viewName of "home" I'd expect an output something like "/WEB-INF/views/home.ftl".

My freemarker bean definitions follow:

    @Bean
public ViewResolver getViewResolver() {
    FreeMarkerViewResolver resolver = new FreeMarkerViewResolver();
    resolver.setCache(false);
    resolver.setPrefix("");
    resolver.setSuffix(".ftl");
    return resolver;

}

@Bean
public FreeMarkerConfig getFreemarkerConfig() {

    Properties props = new Properties();
    props.setProperty("number_format","0.##");
    props.setProperty("locale","en-GB");

    Configuration configuration =   new Configuration();
    configuration.setDefaultEncoding("UTF-8");

    FreeMarkerConfigurer configurer = new FreeMarkerConfigurer();
    configurer.setFreemarkerSettings(props);
    configurer.setConfiguration(configuration);
    configurer.setTemplateLoaderPath("/WEB-INF/views/");

    return configurer;

}
1

1 Answers

0
votes

Junits test case

@Test public void insert() throws Exception { this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build(); mockMvc.perform(post("/insert")).andDo(print()) .andExpect(status().isOk()) .andExpect(forwardedUrl("/WEB-INF/test.jsp")); }

Here "insert" will be replaced with your Request mapping value and "page" will be replaced with the relative location you expect that spring will take