Spring retry XML equivalent to @EnableRetry
Yes, @EnableRetry
on an empty @Configuration
will work (comment by OP).
Just for completeness, here's the equivalent in XML.
<context:annotation-config /><aop:aspectj-autoproxy /><bean class="org.springframework.retry.annotation.RetryConfiguration" />
EDIT
Complete example using XML to enable retry:
@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"); } }}
and
<?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>
and
<?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>
and
foofoofoojava.lang.RuntimeException: test retry
My experience after trying out the above seems a little different as I was trting to find a way of using the XML config approach.
1) I had tried using this feature in my Service implementation class by specifying the @Retryable on specific methods, but WITHOUT the @Configuration and @EnableRetry at the class level. The retry feature did not work.
2) I had also tried adding an empty class with @Configuration and @EnableRetry at the class level. Then, configure that class as a spring bean in XML config. The retry feature did not work here, either.
3) The only way it seems to work is when the @Configuration and @EnableRetry annotations are specified on the Service implementation class.
I am not sure if I am missing anything for Point# 1 and 2.