Skip to content

@Retryable annotation silently ignored when 'open' keyword is forgotten in front of Kotlin method #238

Closed
@rpelissier

Description

@rpelissier

I could not findout why a @Retry annotation was not taken into consideration.
After hours of reading the documentation and trying to improve the log verbosity, I realised the keyword 'open' was missing so the method could be overwritten in order to proxy.

It would be great if you could at least raise a warning when scanning the annotation.

More generally, I could not figure out how to follow the @EnableRetry and @Retry injection process to debug my configuration. It makes the API very hard to use if you are blind troubleshooting configuration issues.

Code to reproduce

import org.junit.jupiter.api.Test
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.retry.annotation.Backoff
import org.springframework.retry.annotation.EnableRetry
import org.springframework.retry.annotation.Retryable
import org.springframework.stereotype.Service

@SpringBootTest
@EnableRetry
open class RetryTest {

    @Autowired
    private lateinit var retryableBean: RetryableBean

    @Test
    fun testRetry() {
        retryableBean.trySomething()
    }
}

class CustomException(message: String) : RuntimeException(message)

@Service
open class RetryableBean {
    
    private val log: Logger = LoggerFactory.getLogger(javaClass),
    private var failureCount: Int = 0


    //Will ignore this method if no 'open' keyword, but no warning in the log
    @Retryable
    open fun trySomething() {
        failureCount++
        log.info("Attempt #$failureCount")
        throw CustomException("Failure #$failureCount.")
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions