Tar*_*ken 8 java spring spring-retry
我必须使用一个项目,我不能使用Java-Config for Spring,但我必须使用XML-Config.现在我正在寻找与Java-Config中的@EnableRetry相当的XML-Config.
我希望这条线能够运作.
@Retryable(SQLException.class)
public void saveOrUpdate(Entity entity)
Run Code Online (Sandbox Code Playgroud)
Gar*_*ell 10
是的,@EnableRetry空的@Configuration将工作(由OP评论).
<context:annotation-config />
<aop:aspectj-autoproxy />
<bean class="org.springframework.retry.annotation.RetryConfiguration" />
Run Code Online (Sandbox Code Playgroud)
编辑
使用XML启用重试的完整示例:
@SpringBootApplication
@ImportResource("context.xml")
public class So31923175Application {
public static void main(String[] args) {
SpringApplication.run(So31923175Application.class, args);
}
@Bean
public ApplicationRunner runner(Foo app) {
return args -> {
try {
app.retry("foo");
}
catch (Exception e) {
e.printStackTrace();
}
};
}
@Component
public static class Foo {
@Retryable
public void retry(String param) {
System.out.println(param);
throw new RuntimeException("test retry");
}
}
}
Run Code Online (Sandbox Code Playgroud)
和
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">
<context:annotation-config />
<aop:aspectj-autoproxy />
<bean class="org.springframework.retry.annotation.RetryConfiguration" />
</beans>
Run Code Online (Sandbox Code Playgroud)
和
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>net.gprussell.filemailer</groupId>
<artifactId>so31923175</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>so31923175</name>
<description>Mail non-empty files passed on the command line</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.retry</groupId>
<artifactId>spring-retry</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Run Code Online (Sandbox Code Playgroud)
和
foo
foo
foo
java.lang.RuntimeException: test retry
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4835 次 |
| 最近记录: |