Skip to content

Commit 65db441

Browse files
committed
Merge pull request #26417 from nguyensach
* pr/26417: Update copyright year of changed file Use try-with-resources statement Closes gh-26417
2 parents 217f6ef + ffbd3b8 commit 65db441

File tree

1 file changed

+15
-17
lines changed

1 file changed

+15
-17
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,30 +16,28 @@
1616

1717
package smoketest.atomikos;
1818

19-
import java.io.Closeable;
20-
2119
import org.springframework.boot.SpringApplication;
2220
import org.springframework.boot.autoconfigure.SpringBootApplication;
23-
import org.springframework.context.ApplicationContext;
21+
import org.springframework.context.ConfigurableApplicationContext;
2422

2523
@SpringBootApplication
2624
public class SampleAtomikosApplication {
2725

2826
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);
3940
}
40-
System.out.println("Count is " + repository.count());
41-
Thread.sleep(100);
42-
((Closeable) context).close();
4341
}
4442

4543
}

0 commit comments

Comments
 (0)