package com.vincent.rsf.server.common.datasource; import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Aspect; import org.springframework.beans.factory.annotation.Value; import org.springframework.core.Ordered; import org.springframework.core.annotation.Order; import org.springframework.stereotype.Component; /** * http-audit 数据源切换 */ @Aspect @Component @Order(Ordered.HIGHEST_PRECEDENCE + 10) public class HttpAuditDataSourceAspect { @Value("${http-audit.datasource:primary}") private String dataSource; @Around("execution(* com.vincent.rsf.httpaudit..*(..))") public Object around(ProceedingJoinPoint joinPoint) throws Throwable { String selected = resolveDataSource(); DataSourceContextHolder.push(selected); try { return joinPoint.proceed(); } finally { DataSourceContextHolder.poll(); } } private String resolveDataSource() { if ("dj-cloud-wms".equalsIgnoreCase(dataSource)) { return DataSourceNames.DJ_CLOUD_WMS; } return DataSourceNames.PRIMARY; } }