-1

In my application I am calling web services. So I thought to implement Spring Retry mechanism to make processing more robust and less prone to failure. This is the first time I am using Spring Retry

I created a Application service class in which I am declaring RetryTemplate and setting RetryPolicy.

But it's throwing below syntax error

"Multiple markers at this line
- Syntax error, insert "Identifier (" to complete MethodHeaderName
- Syntax error on token ".", @ expected after this token
- Syntax error, insert ")" to complete MethodDeclaration" 

Even If I use ctrl+space it's not showing setRetryPolicy() method.

Below is my class:

import java.util.Collections;

import org.springframework.retry.policy.SimpleRetryPolicy;

import org.springframework.retry.support.RetryTemplate;

public class ApplicationServiceRetry {

    SimpleRetryPolicy policy = new SimpleRetryPolicy(5,Collections
            .<Class<? extends Throwable>, Boolean> singletonMap(Exception.class, true));
    RetryTemplate template = new RetryTemplate();
    template.setRetryPolicy(policy);  //it's throwing error here

}

I am referring http://docs.spring.io/spring-batch/reference/html/retry.html. Here I am using Spring-retry 1.1.5.RELEASE.

Gary Russell
  • 166,535
  • 14
  • 146
  • 179
jaswanth
  • 1
  • 5
  • Java code that isn't a field declaration (your first 2 lines, maybe unintentionally) can not exist outside of methods (or initializers). You'll have to put `template.setRetryPolicy(policy); ` in a place where it's legal. – zapl Jun 23 '17 at 20:33

1 Answers1

0

??

template.setRetryPolicy(policy);

You can't just put arbitrary code there in a class - it has to be in a method, or an initialization block...

public class ApplicationServiceRetry {

    SimpleRetryPolicy policy = new SimpleRetryPolicy(5,
            Collections.<Class<? extends Throwable>, Boolean> singletonMap(Exception.class, true));

    RetryTemplate template = new RetryTemplate();

    {
        template.setRetryPolicy(policy);
    }

}
Gary Russell
  • 166,535
  • 14
  • 146
  • 179