#
cl
2026-04-20 7f582fee8b71e3ccf9e2b0e2f3c9574f5b124d76
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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;
    }
}