In a spring boot application where I have two dataSources,
I need to select the proper dataSource using @Transactional annotation with the following parameters:
- String
value(required) - Boolean
readOnly(default: false)
I want to create an @interface so I do not have to type the value (chances a developer make a mistake is motivating the decision)
So this needs to be written in a class :
@Transactional("transactionManager2") I have created the following @interface:
@Target({ElementType.METHOD, ElementType.TYPE}) @Retention(RetentionPolicy.RUNTIME) @Transactional("transactionManager2") public @interface TransactionManager2Tx { } This annotation replace @Transactional("transactionManager2") and it is working well.
However, I cannot pass the other parameters. For example, this is not possible:
@TransactionManager2Tx(readOnly = true) How can I achieve this?