Under WildFly 10.1.0.Final I am getting:

java.lang.IllegalAccessError: class org.springframework.data.rest.webmvc.RepositoryEntityController cannot access its superclass org.springframework.data.rest.webmvc.AbstractRepositoryRestController

This issue started to happen when I added Spring Data Rest configuration with all the necessary dependencies into the project.

I noticed that issue cannot be reproduced when I comment<context:load-time-weaver />tag inside the applicationContext.xml.

This is a sample app that reproduces the problem: https://github.com/emaysyuk/spring-boot-data-rest

Comment From: emaysyuk

I have prepared additional sample project that demonstrates that issue doesn't occur while using traditional xml configuration (without Spring Boot):

https://github.com/emaysyuk/spring-data-rest-xml-config

Comment From: philwebb

Do you have a complete stack trace from the "cannot access its superclass" error that you can attach?

Comment From: wilkinsona

I've seen this happen in the past, but only when there are two class loaders.

When a package is defined it's associated with a particular class loader. If two class loaders define the same package they're not actually the same and anything that's package-private in a class loaded by one class loader won't be visible to a class loaded by another class loader even though the classes appear to be in the same package.

Comment From: emaysyuk

@philwebb The attached file is a complete stack trace. log.txt

Comment From: emaysyuk

@wilkinsona you are absolutely right.

I have found a root cause of this issue.

AbstractApplicationContext:655

At this place Spring sets ContextTypeMatchClassLoader as a temp classLoader

...

SimpleMetadataReaderFactory:98

this.resourceLoader.getClassLoader returns JBoss classLoader (not temporarily ContextTypeMatchClassLoader)

SimpleMetadataReader:63

SimpleMetadataReader passes JBoss classloader into AnnotationMetadataReadingVisitor object

AnnotationMetadataReadingVisitor:134

AnnotationMetadataReadingVisitor passes wrong class loader to AnnotationReadingVisitorUtils

AnnotationReadingVisitorUtils:78

Spring uses wrong classLoader to load org.springframework.data.rest.webmvc.RepositoryRestController and its parent org.springframework.data.rest.webmvc.AbstractRepositoryRestController and defines package for AbstractRepositoryRestController

... ContextTypeMatchClassLoader:72

ContextTypeMatchClassLoader tries to load org.springframework.data.rest.webmvc.RepositoryEntityController and cannot find its superclass since its package has been defined using JBoss classloader

Comment From: emaysyuk

I think SimpleMetadataReaderFactory has to be refactored to use tempClassLoader from BeanFactory (if it is not null) and a resource class loader in other case.

Comment From: emaysyuk

I have found an open bug (may the same) under Spring Framework Jira: https://jira.spring.io/browse/SPR-10206

Comment From: jhoeller

Let's reuse SPR-10206 for our purposes here. It does indeed hint at the same issue.

We actually intentionally use the standard ClassLoader here since we do not expect annotation types to be weaved... so we naively assumed that they can always be loaded in the factory's regular ClassLoader. It seems that this can cause conflicts with the same package split across the standard and the temp loader here?

Comment From: wilkinsona

Thanks for the analysis, @EugenMaysyuk. I'll close this one as a duplicate of SPR-10206 which I'm now watching.

Comment From: shenyu1997

I met this issue and resolve it by removing

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
        </dependency>