0

I am new to Java Spring boot. -

I've got access to the Freemarker demo -- but how do I get hold of the image path for "\src\main\resources\static\images"

            //Map < String, Object > model = new HashMap < String, Object > ();
            model.put("firstName", "Yashwant");
            model.put("lastName", "Chavan");
            model.put("imgPath", "resources/static/images/");

            mimeMessageHelper.setText(geContentFromTemplate(fmConfiguration, model), true);

            mailSender.send(mimeMessageHelper.getMimeMessage());
        } catch (MessagingException e) {
            System.out.println("ERROR - mimeMessage>>>");
            e.printStackTrace();
        }        
    }

}

public String geContentFromTemplate(Configuration fmConfiguration, Map < String, Object > model) {
    StringBuffer content = new StringBuffer();

    try {
        content.append(FreeMarkerTemplateUtils
            .processTemplateIntoString(fmConfiguration.getTemplate("email-template.html"), model));
    } catch (Exception e) {
        e.printStackTrace();
    }
    return content.toString();
}
kirti
  • 4,499
  • 4
  • 31
  • 60
The Old County
  • 89
  • 13
  • 59
  • 129

1 Answers1

0

Spring already provides this out of the box, where you can map such paths to static URIs.

What you will need to do is, define a Spring Configuration class, extend it with WebMvcConfigurerAdapter

This will give you access to addResourceHandlers method, override that method and provide the path to your static resources along with what URI you want to map it with. Am providing link to another SO answer which does the same thing.

Spring 4 loading static resources

Spring 4 - addResourceHandlers not resolving the static resources

Himanshu Bhardwaj
  • 4,038
  • 3
  • 17
  • 36
  • - I am not really sure on these -- I am using reactjs for the frontend - so it maybe stop gaining access to those images? -- I just want to expose an image location folder just for the emails -- maybe stash them where the template is being fetched from – The Old County Sep 07 '17 at 22:28
  • I tried creating a configuration - but it had no affect - I am unsure if my reactjs build is now interfering with those routing paths. – The Old County Sep 09 '17 at 08:27