下面列出了怎么用org.springframework.boot.autoconfigure.thymeleaf.ThymeleafAutoConfiguration的API类实例代码及写法,或者点击链接到github查看源代码。
@Before
public void setUp() {
contextRunner = new ApplicationContextRunner()
.withPropertyValues(
"mail.smtp.host="+ServerSetupTest.SMTP.getBindAddress(),
"mail.smtp.port="+ServerSetupTest.SMTP.getPort(),
"ogham.sms.smpp.host=127.0.0.1",
"ogham.sms.smpp.port="+smppServer.getPort(),
"spring.freemarker.suffix=")
.withConfiguration(of(TestConfig.class, ThymeleafAutoConfiguration.class, FreeMarkerAutoConfiguration.class, OghamSpringBoot2AutoConfiguration.class));
}
@Test
public void oghamWithThymeleafAutoConfigShouldUseSpringTemplateEngine() throws Exception {
contextRunner = contextRunner.withConfiguration(of(ThymeleafAutoConfiguration.class, OghamSpringBoot2AutoConfiguration.class));
contextRunner.run((context) -> {
MessagingService messagingService = context.getBean(MessagingService.class);
checkEmail(messagingService);
checkSms(messagingService);
OghamInternalAssertions.assertThat(messagingService)
.thymeleaf()
.all()
.engine(isA(SpringTemplateEngine.class));
});
}
@Test
public void useCustomThymeleafBean() throws Exception {
contextRunner = contextRunner.withConfiguration(of(CustomThymeleafEngineConfig.class, ThymeleafAutoConfiguration.class, OghamSpringBoot2AutoConfiguration.class));
contextRunner.run((context) -> {
MessagingService messagingService = context.getBean(MessagingService.class);
checkEmail(messagingService);
checkSms(messagingService);
OghamInternalAssertions.assertThat(messagingService)
.thymeleaf()
.all()
.engine(isA(CustomSpringTemplateEngine.class));
});
}
@Test
public void oghamWithThymeleafAutoConfigShouldUseSpringTemplateEngine() throws Exception {
context.register(ThymeleafAutoConfiguration.class, OghamSpringBoot1AutoConfiguration.class);
context.refresh();
MessagingService messagingService = context.getBean(MessagingService.class);
checkEmail(messagingService);
checkSms(messagingService);
OghamInternalAssertions.assertThat(messagingService)
.thymeleaf()
.all()
.engine(isA(SpringTemplateEngine.class));
}
@Test
public void useCustomThymeleafBean() throws Exception {
context.register(CustomThymeleafEngineConfig.class, ThymeleafAutoConfiguration.class, OghamSpringBoot1AutoConfiguration.class);
context.refresh();
MessagingService messagingService = context.getBean(MessagingService.class);
checkEmail(messagingService);
checkSms(messagingService);
OghamInternalAssertions.assertThat(messagingService)
.thymeleaf()
.all()
.engine(isA(CustomSpringTemplateEngine.class));
}
@Before
public void setUp() {
context = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(context,
"mail.smtp.host="+ServerSetupTest.SMTP.getBindAddress(),
"mail.smtp.port="+ServerSetupTest.SMTP.getPort(),
"ogham.sms.smpp.host=127.0.0.1",
"ogham.sms.smpp.port="+smppServer.getPort(),
"spring.freemarker.suffix=");
context.register(TestConfig.class, ThymeleafAutoConfiguration.class, FreeMarkerAutoConfiguration.class, OghamSpringBoot1AutoConfiguration.class);
context.refresh();
messagingService = context.getBean(MessagingService.class);
}