我想制作一个像 @PathVariable 这样的自定义注释,将用于参数来为方法提供值,如下所示:
public String subscribe(@PathVariable String date, @PathVariable String text, @PermittedMarkets String[] marketCodes) { //do processing and return something here }
我已经定义了注释:
@Target(ElementType.PARAMETER)
@Retention(RetentionPolicy.RUNTIME)
public @interface PermittedMarkets {
}
和:
@Aspect
@Component
public class MarketsAspect {
@Value("#{${config.market.permitted.marketmapping:{:}}}") //if value is provided, use it or default to empty map
private Map<String,String> roleToMarketCodeMap;
@Before("@annotation(com.org.app.service.security.annotation.PermittedMarkets)")
public String[] before(JoinPoint joinPoint) {
final var grantedAuthorities =
Optional.ofNullable(SecurityContextHolder.getContext().getAuthentication())
.map(Authentication::getAuthorities)
.orElseThrow(() -> new AccessDeniedException("No authorities found"));
return grantedAuthorities.stream()
.map(GrantedAuthority::getAuthority)
.filter(entitlement -> entitlement.contains("app_user"))
.map(A_entitlement -> roleToMarketCodeMap.get(A_entitlement))
.toArray(String[]::new);
}
}
但是,当我使用调试器单步调试时,订阅方法上显示的是以下内容:
调试器根本不会进入 before() 方法,即使上面有断点。