|
1 | 1 | /* |
2 | | - * Copyright 2012-2019 the original author or authors. |
| 2 | + * Copyright 2012-2021 the original author or authors. |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | * you may not use this file except in compliance with the License. |
|
16 | 16 |
|
17 | 17 | package smoketest.atomikos; |
18 | 18 |
|
19 | | -import java.io.Closeable; |
20 | | - |
21 | 19 | import org.springframework.boot.SpringApplication; |
22 | 20 | import org.springframework.boot.autoconfigure.SpringBootApplication; |
23 | | -import org.springframework.context.ApplicationContext; |
| 21 | +import org.springframework.context.ConfigurableApplicationContext; |
24 | 22 |
|
25 | 23 | @SpringBootApplication |
26 | 24 | public class SampleAtomikosApplication { |
27 | 25 |
|
28 | 26 | public static void main(String[] args) throws Exception { |
29 | | - ApplicationContext context = SpringApplication.run(SampleAtomikosApplication.class, args); |
30 | | - AccountService service = context.getBean(AccountService.class); |
31 | | - AccountRepository repository = context.getBean(AccountRepository.class); |
32 | | - service.createAccountAndNotify("josh"); |
33 | | - System.out.println("Count is " + repository.count()); |
34 | | - try { |
35 | | - service.createAccountAndNotify("error"); |
36 | | - } |
37 | | - catch (Exception ex) { |
38 | | - System.out.println(ex.getMessage()); |
| 27 | + try (ConfigurableApplicationContext context = SpringApplication.run(SampleAtomikosApplication.class, args)) { |
| 28 | + AccountService service = context.getBean(AccountService.class); |
| 29 | + AccountRepository repository = context.getBean(AccountRepository.class); |
| 30 | + service.createAccountAndNotify("josh"); |
| 31 | + System.out.println("Count is " + repository.count()); |
| 32 | + try { |
| 33 | + service.createAccountAndNotify("error"); |
| 34 | + } |
| 35 | + catch (Exception ex) { |
| 36 | + System.out.println(ex.getMessage()); |
| 37 | + } |
| 38 | + System.out.println("Count is " + repository.count()); |
| 39 | + Thread.sleep(100); |
39 | 40 | } |
40 | | - System.out.println("Count is " + repository.count()); |
41 | | - Thread.sleep(100); |
42 | | - ((Closeable) context).close(); |
43 | 41 | } |
44 | 42 |
|
45 | 43 | } |
0 commit comments