Summary

Annotations of generic super methods are not found.

Expected Behavior

Annotations of generic super methods (including interfaces) are found. Therefore super types of the given parameter types must be valid while traversing superclases/interfaces.

Configuration

none

Version

spring-boot 1.5.1.RELEASE

Sample

This is a minimal setup to reproduce the issue

import org.junit.Assert;
import org.junit.Test;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.transaction.annotation.Transactional;

import java.lang.reflect.Method;

public class AnnotationUtilsTest {

    public interface A<T> {
        @Transactional // A random annotation
        T method(T t);
    }

    public static class B implements A<String> {
        @Override
        public String method( String s ) {
            return s;
        }
    }

    @Test
    public void annotationForMethodInRuntime()
        throws NoSuchMethodException {
        Method method = B.class.getMethod( "method", String.class );
        Assert.assertNotNull( "method not found", method );
        Transactional annotation = AnnotationUtils.findAnnotation( method, Transactional.class );
        Assert.assertNotNull( "annotation not found", annotation );
    }

    @Test
    public void thisWorksButItsNotWhatYouExpect()
        throws NoSuchMethodException {
        Method method = B.class.getMethod( "method", Object.class );
        Assert.assertNotNull( "method not found", method );
        Transactional annotation = AnnotationUtils.findAnnotation( method, Transactional.class );
        Assert.assertNotNull( "annotation not found", annotation );
    }
}

Comment From: sumanas27

Please use Spring boot 2.0 Plus versions and the problem will be solved

Comment From: jzheaux

This seems to be an issue for Spring core instead of Spring Security. If this is still an issue, I'd recommend logging it there.