Здравствуйте, у меня есть собственная аннотация, в которую я хочу передать значение из properties, но это никак не получается. Как можно это сделать?
Сама аннотация
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface ServerNameMapping {
String[] value();
}
Место где получаю значение
public class ServerNameRequestMappingHandlerMapping extends RequestMappingHandlerMapping {
@Override
protected RequestCondition<?> getCustomTypeCondition(Class<?> handlerType) {
ServerNameMapping serverNameMapping = AnnotationUtils.findAnnotation(handlerType, ServerNameMapping.class);
if (serverNameMapping != null) {
return new ServerNameRequestConditional(new HashSet<>(List.of(serverNameMapping.value())));
}
return super.getCustomTypeCondition(handlerType);
}
@Override
protected RequestCondition<?> getCustomMethodCondition(Method method) {
ServerNameMapping serverNameMapping = AnnotationUtils.findAnnotation(method, ServerNameMapping.class);
if (serverNameMapping != null) {
return new ServerNameRequestConditional(new HashSet<>(List.of(serverNameMapping.value())));
}
return super.getCustomMethodCondition(method);
}
}
Вот так использую
@ServerNameMapping("${app.externalApiHostname}")
@RequestMapping("/api/v1")
@RestController
public class ExternalApiController {
@GetMapping
public void test() {
System.out.println("ExternalApiController");
}
}