Skip to content

Revise ClassUtils.isPresent for exposing resolution exceptions in jlinked modules [SPR-17018] #21556

Closed
@spring-projects-issues

Description

@spring-projects-issues

J. Pablo Fernández opened SPR-17018 and commented

I know this is not a bug in 5.0.7 because it's modular Java is not supported, but I think this will be a bug once it is. I'm using the ModiTect maven plugin to inject many of the Spring jars with a definition of their module (module-info.java). I'm happy to share the results as it might help speed things up for others.

One of the issues I run into is this exception:

Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: org.springframework.beans.factory.aspectj.AnnotationBeanConfigurerAspect not found.
Could not configure Spring Data JPA auditing-feature because spring-aspects.jar is not on the classpath!
If you want to use auditing please add spring-aspects.jar to the classpath.
        at [email protected]/org.springframework.data.jpa.repository.config.JpaAuditingRegistrar.registerBeanConfigurerAspectIfNecessary(JpaAuditingRegistrar.java:124)
        at [email protected]/org.springframework.data.jpa.repository.config.JpaAuditingRegistrar.registerBeanDefinitions(JpaAuditingRegistrar.java:88)
        at [email protected]/org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.lambda$loadBeanDefinitionsFromRegistrars$1(ConfigurationClassBeanDefinitionReader.java:358)
        at java.base/java.util.LinkedHashMap.forEach(LinkedHashMap.java:684)
        at [email protected]/org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsFromRegistrars(ConfigurationClassBeanDefinitionReader.java:357)
        at [email protected]/org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForConfigurationClass(ConfigurationClassBeanDefinitionReader.java:145)
        at [email protected]/org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitions(ConfigurationClassBeanDefinitionReader.java:117)
        at [email protected]/org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:328)
        at [email protected]/org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:233)
        at [email protected]/org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:273)
        at [email protected]/org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:93)
        at [email protected]/org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694)
        at [email protected]/org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532)
        at [email protected]/org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759)
        at [email protected]/org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:395)
        at [email protected]/org.springframework.boot.SpringApplication.run(SpringApplication.java:327)
        at [email protected]/org.springframework.boot.SpringApplication.run(SpringApplication.java:1255)
        at [email protected]/org.springframework.boot.SpringApplication.run(SpringApplication.java:1243)
        at tech.flexpoint.dashmanserver/tech.flexpoint.dashmanserver.DashmanServerApplication.main(DashmanServerApplication.java:13)

I don't think this is an access problem because I already defined the module this way (being on the side of making it work at all costs):

module spring.aspects {
    exports org.springframework.beans.factory.aspectj;
    opens org.springframework.beans.factory.aspectj;
}

and of course spring.core requires spring.aspects.

I think the problem is that the actual code won't work with the ClassLoader when jlinked. This wouldn't be the first time I found class loaders behaving differently on Java 9 or 10:

https://stackoverflow.com/questions/49702287/getresourceasstream-returning-null-in-java-10

One of the issues is that I cannot replicate this problem while I can attach a debugger, so, I can't figure exactly what's going on. I'm reporting this here in case someone that's much more familiar with the code can point me in the right direction on how to figure out what's happening here and maybe coming up with a fix.

 


Affects: 5.0.7

Reference URL: https://stackoverflow.com/questions/51207237/class-not-found-in-spring-when-using-java-modules-and-jlink

Issue Links:

Referenced from: commits 833343f

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions