How to programmatically set annotation property / attribute?

Therefore, I need to set the timeout parameter for the @Transactional annotation. This property will be obtained from the properties file, which I cannot do, since I meet "The value of the Transactional.timeout annotation attribute must be a constant expression." Something like that

@Value("${mytimeout}")
private int myTimeout;

@Transactional(timeout=myTimeout)
public void myMethod(){
}

The only time a timeout attribute can be set by a variable is when the final variable.

So, I was thinking whether it is possible to programmatically set the timeout property when using the @Transaction annotation. Or in any other way I can set this attribute Thanks!

+4
source share
1
  • - , defaultTimeout

  • AnnotationTransactionAttributeSource TransactionAnnotationParser, <tx:annotation-drivern> beans, .

    TransactionAnnotationParser TransactionDefinition , .

  • - @Transactional TransactionTemplate.

+1

Source: https://habr.com/ru/post/1534601/


All Articles