Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@Recover on interface instead of implementation class #75

Closed
hwang251 opened this issue Feb 27, 2017 · 1 comment
Closed

@Recover on interface instead of implementation class #75

hwang251 opened this issue Feb 27, 2017 · 1 comment

Comments

@hwang251
Copy link

hwang251 commented Feb 27, 2017

I'm having a similar issue with @Recover that is similar to the linked issue #32. In order to make it work it has to be on the interface and not the implementing class.

I used the following class and test

public interface TestService {

    void doStuff();

    void recover();
}
@Named
public class TestServiceImpl implements TestService {

    @Retryable
    public void doStuff() {
    }

    @Recover
    public void recover() {
        System.out.println("recover");
    }
}
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
public static class RetryTests extends SpringRetryTest {

        @Inject
        private TestService testService;

        @Test
        public void testRecover() {
            testService.doStuff();
            verify(testService, times(3)).doStuff();
        }

        @After
        public void validate() {
            validateMockitoUsage();
        }

        @Configuration
        @EnableRetry
        public static class SpringConfig {

            @Bean
            public TestService testService() {
                TestService testService = mock(TestServiceImpl.class);
                Mockito.doThrow(new RuntimeException())
                        .doThrow(new RuntimeException())
                        .doThrow(new RuntimeException())
                        .when(testService).doStuff();
                return testService;
        }
    }
}

But if you move the @Recover to the interface it works.

@dsyer
Copy link
Member

dsyer commented Dec 12, 2017

You probably need @EnableRetry(proxyTargetClass=true) there to make the annotations in the implementation class visible in the proxy. I don't think there's a better way to solve this problem.

@dsyer dsyer closed this as completed Dec 12, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants