在数据库不可用的情况下,我需要重试3次执行我的服务方法。为此,我使用Spring重试模板。但是使用@Transactional注释时,当DB不可用时,无法捕获特定的异常。
@Configuration
public class RetryTemplateConfig {
@Bean
public RetryTemplate createRetryTemplate(){
RetryTemplate retryTemplate = new RetryTemplate();
FixedBackOffPolicy fixedBackOffPolic
我想知道关于Spring @Retryable注释的一些东西。
我希望根据异常类型实现@Retryable maxAttemps计数,例如:
if Exception type is ExceptionA:
@Retryable(value = ExceptionA.class, maxAttempts = 2)
if Exception type is ExceptionB:
@Retryable(value = ExceptionB.class, maxAttempts = 5)
是否可以使用@Retryable注释来完成,或者是否有任何建议?
我在Spring boot中写了一个Retryable。它将重试5次,回退时间为5秒。如果满足某些条件,我也希望在5次迭代之前退出。就像是 @Retryable(value = {SomeException.class}, maxAttempts = 5, backoff = @Backoff(delay = 5000))
public void checkForProcessed() throws SomeException {
if(someCondition) {
//come out of the retryable before r
我最近添加了Spring@Retryable来处理502错误,而不是来自目标服务器的适当响应。(用retrofit2)。
下面只是伪代码,但原始代码以类似的方式处理异常。
class BadGatewayException : RuntimeException
@Retryable(include = [BadGatewayException::class])
class A {
private fun handle(block: () -> Call<T>): T {
try {
val response = val re
有一个实体:
@Entity
class A {
...
@Version
int version;
}
以乐观方式实现的A实例更新:
@Transactional(rollbackFor = {StaleStateException.class})
@Retryable(value = {StaleStateException.class})
public void updateA() {
A a = findA();
B b = new B();
// Update "a" somehow
a.update();
如何使用@Retryable()注释在spring-retry中注册监听器?
@Bean
public RetryListener myRetryListener() {
return new MyRetryListener();
}
@Service
public class SampleService {
private int cnt = 1;
@Retryable(RuntimeException.class)
public void retryMethod(int x) throws Exception {
System.out.printl
WebFlux Spring @Transactional注释与反应性MongoDB一起工作吗?
我将WebFlux Spring与反应性MongoDB一起使用,例如:
id 'org.springframework.boot' version '2.6.7'
...
implementation 'org.springframework.boot:spring-boot-starter-webflux'
implementation 'org.springframework.boot:spring-boo
在我将@Retryable注释添加到我的spring-data-cassandra存储库接口后,现在应用程序无法启动,并出现以下异常:
应用程序启动失败
The bean 'airingDao' could not be injected as a 'my.dao.AiringDao' because it is a JDK dynamic proxy that implements:
org.springframework.data.cassandra.repository.CassandraRepository
操作:
Consider injecting
我有一个由Spring代理的服务类,如下所示:
@Service
@Transactional
open class MyService { ... }
如果删除open修饰符,Spring会抱怨它需要代理类来应用@Transactional注释调整。
但是,这会在调用代理服务上的函数时引发问题,该服务试图访问一个变量:
@Service
@Transactional
open class MyService {
protected val internalVariable = ...
fun doWork() {
internalVariable.exec