Java Code Examples for org.thymeleaf.spring5.SpringTemplateEngine#addTemplateResolver()

The following examples show how to use org.thymeleaf.spring5.SpringTemplateEngine#addTemplateResolver() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MailNotifierTest.java    From Moss with Apache License 2.0 6 votes vote down vote up
@Before
public void setup() {
    repository = mock(InstanceRepository.class);
    when(repository.find(instance.getId())).thenReturn(Mono.just(instance));

    sender = mock(JavaMailSender.class);
    when(sender.createMimeMessage()).thenAnswer(args -> new MimeMessage(Session.getInstance(new Properties())));

    SpringTemplateEngine templateEngine = new SpringTemplateEngine();
    ClassLoaderTemplateResolver resolver = new ClassLoaderTemplateResolver();
    resolver.setTemplateMode(TemplateMode.HTML);
    resolver.setCharacterEncoding(StandardCharsets.UTF_8.name());
    templateEngine.addTemplateResolver(resolver);

    notifier = new MailNotifier(sender, repository, templateEngine);
    notifier.setTo(new String[]{"[email protected]"});
    notifier.setCc(new String[]{"[email protected]"});
    notifier.setFrom("SBA <[email protected]>");
    notifier.setBaseUrl("http://localhost:8080");
    notifier.setTemplate("/META-INF/spring-boot-admin-server/mail/status-changed.html");
}
 
Example 2
Source File: MailNotifierTest.java    From spring-boot-admin with Apache License 2.0 6 votes vote down vote up
@BeforeEach
public void setup() {
	repository = mock(InstanceRepository.class);
	when(repository.find(instance.getId())).thenReturn(Mono.just(instance));

	sender = mock(JavaMailSender.class);
	when(sender.createMimeMessage()).thenAnswer((args) -> new MimeMessage(Session.getInstance(new Properties())));

	SpringTemplateEngine templateEngine = new SpringTemplateEngine();
	ClassLoaderTemplateResolver resolver = new ClassLoaderTemplateResolver();
	resolver.setTemplateMode(TemplateMode.HTML);
	resolver.setCharacterEncoding(StandardCharsets.UTF_8.name());
	templateEngine.addTemplateResolver(resolver);

	notifier = new MailNotifier(sender, repository, templateEngine);
	notifier.setTo(new String[] { "[email protected]" });
	notifier.setCc(new String[] { "[email protected]" });
	notifier.setFrom("SBA <[email protected]>");
	notifier.setBaseUrl("http://localhost:8080");
	notifier.setTemplate("/META-INF/spring-boot-admin-server/mail/status-changed.html");
}
 
Example 3
Source File: AdminServerNotifierAutoConfiguration.java    From Moss with Apache License 2.0 5 votes vote down vote up
@Bean
public TemplateEngine mailNotifierTemplateEngine() {
    SpringResourceTemplateResolver resolver = new SpringResourceTemplateResolver();
    resolver.setApplicationContext(this.applicationContext);
    resolver.setTemplateMode(TemplateMode.HTML);
    resolver.setCharacterEncoding(StandardCharsets.UTF_8.name());

    SpringTemplateEngine templateEngine = new SpringTemplateEngine();
    templateEngine.addTemplateResolver(resolver);
    return templateEngine;
}
 
Example 4
Source File: EmailMessageTemplateAutoConfiguration.java    From magic-starter with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Bean(MessageConstants.EMAIL_TEMPLATE_ENGINE_BEAN)
public TemplateEngine templateEngine(@Qualifier(MessageConstants.EMAIL_TEMPLATE_RESOLVER_BEAN) SpringResourceTemplateResolver templateResolver) {
	SpringTemplateEngine engine = new SpringTemplateEngine();
	engine.addDialect(new Java8TimeDialect());
	engine.addTemplateResolver(templateResolver);
	engine.getConfiguration();

	return engine;
}
 
Example 5
Source File: TemplateConfig.java    From zhcet-web with Apache License 2.0 5 votes vote down vote up
@Bean(name = "extraTemplateEngine")
public TemplateEngine emailTemplateEngine() {
    final SpringTemplateEngine templateEngine = new SpringTemplateEngine();
    // Resolver for TEXT
    templateEngine.addTemplateResolver(textTemplateResolver());
    // Resolver for HTML
    templateEngine.addTemplateResolver(htmlTemplateResolver());
    // Resolver for JS
    templateEngine.addTemplateResolver(jsTemplateResolver());
    // Resolver for HTML (editable) as string
    templateEngine.addTemplateResolver(stringTemplateResolver());
    return templateEngine;
}
 
Example 6
Source File: ThymeleafConfiguration.java    From graviteeio-access-management with Apache License 2.0 5 votes vote down vote up
@Bean
public SpringTemplateEngine getTemplateEngine() {
    SpringTemplateEngine templateEngine = new SpringTemplateEngine();
    templateEngine.setEnableSpringELCompiler(true);

    // set template resolvers
    TemplateResolver overrideTemplateResolver = (TemplateResolver) overrideTemplateResolver();
    overrideTemplateResolver.setTemplateEngine(templateEngine);
    templateEngine.setTemplateResolver(overrideTemplateResolver);
    templateEngine.addTemplateResolver(defaultTemplateResolver());
    return templateEngine;
}
 
Example 7
Source File: AdminServerNotifierAutoConfiguration.java    From spring-boot-admin with Apache License 2.0 5 votes vote down vote up
@Bean
public TemplateEngine mailNotifierTemplateEngine() {
	SpringResourceTemplateResolver resolver = new SpringResourceTemplateResolver();
	resolver.setApplicationContext(this.applicationContext);
	resolver.setTemplateMode(TemplateMode.HTML);
	resolver.setCharacterEncoding(StandardCharsets.UTF_8.name());

	SpringTemplateEngine templateEngine = new SpringTemplateEngine();
	templateEngine.addTemplateResolver(resolver);
	return templateEngine;
}