Below is my custom annotation.
@Target({ ElementType.METHOD, ElementType.TYPE })
@Retention(RetentionPolicy.RUNTIME)
@Transactional(value = TransactionalCode.MANAGER, readOnly = true)
public @interface FinanceReadTx {}
I want to do something with the "MyAnnotation" so I declared @Around
and method like below.
@Aspect
@Component
public class TransactionalInterceptor implements Ordered {
@Around("within(@org.springframework.transaction.annotation.Transactional *) || " +
"within(@(@org.springframework.transaction.annotation.Transactional *) *)")
public Object proceed(ProceedingJoinPoint pjp) throws Throwable {
try {
setDbType(pjp);
Object result = pjp.proceed();
DataSourceContextHolder.clearDataSourceType();
return result;
} finally {
// restore state
DataSourceContextHolder.clearDataSourceType();
}
}
// ...
}
The below service is "Autowired" by other classes. so I think it is not the problem related to AOP proxy.
@Service
public class UnconfirmedReportService {
private static final int PREVIEW_SIZE = 8;
@Autowired
private UnconfirmedReportRepository unconfirmedReportRepository;
// ...
@FinanceHikariReadTx
public List<UnconfirmedExcelDownloadView> getExcelData(UnconfirmedSearchCondition condition) {
List<UnconfirmedExcelDownloadView> excelData = newArrayList();
excelData.addAll(newArrayList(getPurchaseReportDetailExcel(condition)));
return excelData;
}
// ...
}
The below code calls the above service
@Slf4j
@Component
public class UnconfirmedDashboardDetailExcelReader extends SellerExcelReaderTemplate<UnconfirmedExcelDownloadView, UnconfirmedSearchCondition> {
@Autowired
private UnconfirmedReportService unconfirmedReportservice;
@Override public List<UnconfirmedExcelDownloadView> read(String conditionJson) {
UnconfirmedSearchCondition condition = transformCondition(conditionJson);
List<UnconfirmedExcelDownloadView> viewList = unconfirmedReportservice.getExcelData(condition);
return viewList;
}
// ...
}
If the @MyAnnotation
is annotated to a class, the proceed() is called but If a method is with the annotation like above code, it doesn't work. I want it to work with only methods.
What I try to solve this?