Я размышлял о функции Java, которая оценивает значения аннотации во время компиляции, и, похоже, действительно делает сложные внешние примечания аннотации.
Однако я не уверен, действительно ли это невозможно, поэтому я буду благодарен за любые предложения или окончательные ответы на это.
Более того, я пытаюсь вытеснить значение аннотации, которое контролирует задержки между вызовами запланированных методов в Spring, например:
public class SomeClass {
private Properties props;
private static final long delay = 0;
@PostConstruct
public void initializeBean() {
Resource resource = new ClassPathResource("scheduling.properties");
props = PropertiesLoaderUtils.loadProperties(resource);
delay = props.getProperties("delayValue");
}
@Scheduled(fixedDelay = delay)
public void someMethod(){
// perform something
}
}
Предположим, что scheduling.properties
находится в пути к классам и содержит ключ свойства delayValue
вместе с его соответствующим длинным значением.
Теперь этот код имеет очевидные ошибки компиляции, так как мы пытаемся присвоить значение переменной final
, но это обязательно, поскольку мы не можем назначить переменную значение аннотации, если оно не является static final
.
Есть ли способ обойти это? Я думал о Spring пользовательских аннотации, но проблема с корнем остается - как назначить внешнее значение аннотации?
Любая идея приветствуется.
EDIT: небольшое обновление. Кварцевая интеграция является излишним для этого примера. Нам просто нужно выполнить периодическое выполнение с разрешением не более минуты и все.