Created
November 7, 2015 00:55
-
-
Save lsiu/6c87f4e96408929ed263 to your computer and use it in GitHub Desktop.
Example of manually bootstraping SpringBoot AutoConfiguration with conditions depending on existance of spring boot properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
void "can send email without errors"() { | |
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext() | |
StandardEnvironment environment = new StandardEnvironment() | |
InputStream ins = Resources.getResourceAsStream("/application.properties") | |
Properties props = new Properties() | |
props.load(ins as InputStream); | |
Closeables.closeQuietly(ins); | |
environment.propertySources.addFirst(new PropertiesPropertySource("application", props)) | |
context.setEnvironment(environment) | |
context.register(MailSenderAutoConfiguration) | |
context.refresh() | |
context.start() | |
println context.getBean(MailerTest).host | |
JavaMailSender mailSender = context.getBean(JavaMailSender) | |
SpringTemplateEngine templateEngine = new SpringTemplateEngine(); | |
templateEngine.addTemplateResolver(new ClassLoaderTemplateResolver(prefix: "templates/", templateMode: "HTML5", order: 1)) | |
Mailer mailer = new Mailer(mailSender, templateEngine) | |
mailer.merchantCreated(new Merchant(merchantName: "Test Merchant Name", contactName: "Contact Name", emailAddress: "leonard.siu@trioloop.com")) | |
println "Method returned" | |
ForkJoinPool.commonPool().awaitQuiescence(30, TimeUnit.SECONDS) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment