I have been working on a demonstration application to understand FreeMarker templates with Spring Boot. I like FreeMarker templates, but I can't get images to display on the web pages. I have tried everything I can think of as far as the placement of the image and image directory, but nothing has worked. I hope that someone can point out my problem, since if I can't solve this issue, I can't use FreeMarker.
My project directory looks like:
I am using Spring Boot 2.1.1.
I use Bootstrap for page formatting. Here is the Bootstrap/HTML that references the image:
<div class="row">
<div class="col-md-12">
<img src="/img/snowy_egret_thumb.jpg" />
</div>
</div> <!-- row -->
I have thought that perhaps I am missing something in the FreeMarker configuration, but I have not found anything. My FreeMarker Configuration class is shown below:
@Configuration
@EnableWebMvc
@ComponentScan({"cognitodemo.freemarker"})
public class AppConfig implements WebMvcConfigurer,
ApplicationContextAware {
private ApplicationContext applicationContext = null;
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
this.applicationContext = applicationContext;
}
@Bean
@Description("FreeMarker View Resolver")
public FreeMarkerViewResolver viewResolver(){
FreeMarkerViewResolver viewResolver = new FreeMarkerViewResolver();
viewResolver.setCache(false);
viewResolver.setPrefix("");
viewResolver.setSuffix(".html");
return viewResolver;
}
@Bean
public FreeMarkerConfigurer freemarkerConfig() {
FreeMarkerConfigurer freeMarkerConfigurer = new
FreeMarkerConfigurer();
freeMarkerConfigurer.setTemplateLoaderPath("/WEB-INF/views/");
return freeMarkerConfigurer;
}
}
When I run the application with Spring Boot I get the following warning:
WARN[0;39m [35m13617[0;39m [2m---[0;39m [2m[ restartedMain][0;39m [36mo.s.b.a.f.FreeMarkerAutoConfiguration [0;39m [2m:[0;39m Cannot find template location(s): [classpath:/templates/] (please add some templates, check your FreeMarker configuration, or set spring.freemarker.checkTemplateLocation=false)
However, the application pages work properly. It's just that the image will not load.
Any help would be greatly appreciated. Many thanks in advance.

