Browse Source

Add support for Spring Retry in CLI

pull/3211/merge
Dave Syer 11 years ago
parent
commit
2c829c7229
  1. 30
      spring-boot-cli/samples/retry.groovy
  2. 49
      spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/autoconfigure/SpringRetryCompilerAutoConfiguration.java
  3. 2
      spring-boot-cli/src/main/resources/META-INF/services/org.springframework.boot.cli.compiler.CompilerAutoConfiguration
  4. 8
      spring-boot-cli/src/test/java/org/springframework/boot/cli/SampleIntegrationTests.java
  5. 6
      spring-boot-dependencies/pom.xml

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

@ -0,0 +1,30 @@ @@ -0,0 +1,30 @@
package org.test
@EnableRetry
@Component
class Example implements CommandLineRunner {
@Autowired
private MyService myService
void run(String... args) {
println "Hello ${this.myService.sayWorld()} From ${getClass().getClassLoader().getResource('samples/retry.groovy')}"
}
}
@Service
class MyService {
static int count = 0
@Retryable
String sayWorld() {
if (count++==0) {
throw new IllegalStateException("Planned")
}
return "World!"
}
}

49
spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/autoconfigure/SpringRetryCompilerAutoConfiguration.java

@ -0,0 +1,49 @@ @@ -0,0 +1,49 @@
/*
* Copyright 2012-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.cli.compiler.autoconfigure;
import org.codehaus.groovy.ast.ClassNode;
import org.codehaus.groovy.control.customizers.ImportCustomizer;
import org.springframework.boot.cli.compiler.AstUtils;
import org.springframework.boot.cli.compiler.CompilerAutoConfiguration;
import org.springframework.boot.cli.compiler.DependencyCustomizer;
/**
* {@link CompilerAutoConfiguration} for Spring Retry.
*
* @author Dave Syer
*/
public class SpringRetryCompilerAutoConfiguration extends CompilerAutoConfiguration {
@Override
public boolean matches(ClassNode classNode) {
return AstUtils.hasAtLeastOneAnnotation(classNode, "EnableRetry", "Retryable",
"Recover");
}
@Override
public void applyDependencies(DependencyCustomizer dependencies) {
dependencies.ifAnyMissingClasses(
"org.springframework.retry.annotation.EnableRetry").add("spring-retry",
"spring-boot-starter-aop");
}
@Override
public void applyImports(ImportCustomizer imports) {
imports.addStarImports("org.springframework.retry.annotation");
}
}

2
spring-boot-cli/src/main/resources/META-INF/services/org.springframework.boot.cli.compiler.CompilerAutoConfiguration

@ -13,8 +13,8 @@ org.springframework.boot.cli.compiler.autoconfigure.TransactionManagementCompile @@ -13,8 +13,8 @@ org.springframework.boot.cli.compiler.autoconfigure.TransactionManagementCompile
org.springframework.boot.cli.compiler.autoconfigure.SpringIntegrationCompilerAutoConfiguration
org.springframework.boot.cli.compiler.autoconfigure.SpringSecurityOAuth2CompilerAutoConfiguration
org.springframework.boot.cli.compiler.autoconfigure.SpringSecurityCompilerAutoConfiguration
org.springframework.boot.cli.compiler.autoconfigure.SpringSecurityOAuth2CompilerAutoConfiguration
org.springframework.boot.cli.compiler.autoconfigure.SpringMobileCompilerAutoConfiguration
org.springframework.boot.cli.compiler.autoconfigure.SpringRetryCompilerAutoConfiguration
org.springframework.boot.cli.compiler.autoconfigure.SpringSocialFacebookCompilerAutoConfiguration
org.springframework.boot.cli.compiler.autoconfigure.SpringSocialLinkedInCompilerAutoConfiguration
org.springframework.boot.cli.compiler.autoconfigure.SpringSocialTwitterCompilerAutoConfiguration

8
spring-boot-cli/src/test/java/org/springframework/boot/cli/SampleIntegrationTests.java

@ -49,6 +49,14 @@ public class SampleIntegrationTests { @@ -49,6 +49,14 @@ public class SampleIntegrationTests {
output.contains("Hello World! From " + scriptUri));
}
@Test
public void retrySample() throws Exception {
String output = this.cli.run("retry.groovy");
URI scriptUri = new File("samples/retry.groovy").toURI();
assertTrue("Wrong output: " + output,
output.contains("Hello World! From " + scriptUri));
}
@Test
public void beansSample() throws Exception {
this.cli.run("beans.groovy");

6
spring-boot-dependencies/pom.xml

@ -130,6 +130,7 @@ @@ -130,6 +130,7 @@
<spring-loaded.version>1.2.3.RELEASE</spring-loaded.version>
<spring-mobile.version>1.1.3.RELEASE</spring-mobile.version>
<spring-plugin.version>1.2.0.RELEASE</spring-plugin.version>
<spring-retry.version>1.1.2.RELEASE</spring-retry.version>
<spring-security.version>4.0.1.RELEASE</spring-security.version>
<spring-security-jwt.version>1.0.3.RELEASE</spring-security-jwt.version>
<spring-security-oauth.version>2.0.7.RELEASE</spring-security-oauth.version>
@ -1521,6 +1522,11 @@ @@ -1521,6 +1522,11 @@
<artifactId>spring-plugin-core</artifactId>
<version>${spring-plugin.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.retry</groupId>
<artifactId>spring-retry</artifactId>
<version>${spring-retry.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-bom</artifactId>

Loading…
Cancel
Save