-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Annotation attributes not available at runtime #535
Comments
Thank you for reporting! Do you have a repo that we can use to easily replicate this? |
The code above will compile and run with just |
FWIW I think this is a duplicate of #999. |
I just verified that the following (modified version of the sample application) passes in the import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.reflect.Method;
import java.util.List;
import org.junit.jupiter.api.Test;
import org.springframework.core.annotation.AnnotatedElementUtils;
import org.springframework.core.annotation.AnnotationAttributes;
import org.springframework.core.annotation.AnnotationUtils;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.entry;
public class AnnotationsTests {
@Test
void test() throws Exception {
Method method = getClass().getMethod("setConverters", List.class);
AnnotationAttributes attributes = AnnotatedElementUtils.getMergedAnnotationAttributes(method, Autowired.class);
assertThat(attributes).containsExactly(entry("required", false));
Autowired ann = method.getAnnotation(Autowired.class);
assertThat(AnnotationUtils.getAnnotationAttributes(ann, true)).containsExactly(entry("required", false));
}
@Autowired(required = false)
public void setConverters(List<Bar> converters) {
}
@Retention(RetentionPolicy.RUNTIME)
@interface Autowired {
boolean required() default true;
}
static class Bar {
}
} Thus, feel free to close this issue. |
Spring has a bunch of use cases for annotations and quite a rich set of convenience classes for introspecting them. They don't seem to fail, much, at runtime in a native image, but they don't actually work either.
Example code:
I have tried to isolate the failure to specific reflective access to the annotation, but haven't been successful. Once (only) I saw some logs from the call to
AnnotatedElementUtils
:The fact that I only saw this once suggests there is perhaps another issue lurking to do with log configuration (Spring uses
commons-logging
which defaults tojava.util.logging
if nothing else is available).The text was updated successfully, but these errors were encountered: