spring-boot/spring-boot-cli/samples/retry.groovy

29 lines
461 B
Groovy
Raw Normal View History

2015-06-12 21:55:07 +08:00
package org.test
@EnableRetry
@Component
class Example implements CommandLineRunner {
@Autowired
private MyService myService
void run(String... args) {
2015-06-16 02:44:44 +08:00
println "Hello ${this.myService.sayWorld()} From ${getClass().getClassLoader().getResource('samples/retry.groovy')}"
2015-06-12 21:55:07 +08:00
}
}
@Service
class MyService {
2015-06-16 02:44:44 +08:00
2015-06-12 21:55:07 +08:00
static int count = 0
@Retryable
String sayWorld() {
if (count++==0) {
throw new IllegalStateException("Planned")
}
return "World!"
}
}