Skip to content
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

JsonTesters do not work in native tests #32858

Closed
mhalbritter opened this issue Oct 24, 2022 · 3 comments
Closed

JsonTesters do not work in native tests #32858

mhalbritter opened this issue Oct 24, 2022 · 3 comments
Assignees
Labels
theme: aot An issue related to Ahead-of-time processing type: bug A general bug
Milestone

Comments

@mhalbritter
Copy link
Contributor

mhalbritter commented Oct 24, 2022

RequestJsonTests from the smoke tests don't work in a native image. I get the following exception:

  JUnit Jupiter:RequestJsonTests:parse()
    MethodSource [className = 'com.example.webmvc.RequestJsonTests', methodName = 'parse', methodParameterTypes = '']
    => org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'null': Unsatisfied dependency expressed through field 'tester': No qualifying bean of type 'org.springframework.boot.test.json.JacksonTester<com.example.webmvc.dto.Request>' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
       org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.resolveFieldValue(AutowiredAnnotationBeanPostProcessor.java:744)
       org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:724)
       org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:127)
       org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.processInjection(AutowiredAnnotationBeanPostProcessor.java:506)
       org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependenciesInAotMode(DependencyInjectionTestExecutionListener.java:153)
       [...]
     Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.boot.test.json.JacksonTester<com.example.webmvc.dto.Request>' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
       org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoMatchingBeanFound(DefaultListableBeanFactory.java:1782)
       org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1341)
       org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1295)
       org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.resolveFieldValue(AutowiredAnnotationBeanPostProcessor.java:741)
       [...]

reproducer: run nativeTest in the webmvc-tomcat smoke tests.

@mhalbritter mhalbritter added type: bug A general bug theme: aot An issue related to Ahead-of-time processing labels Oct 24, 2022
@mhalbritter mhalbritter added this to the 3.0.0-RC2 milestone Oct 24, 2022
@wilkinsona
Copy link
Member

The same failures occur on the JVM when running AOT-processed tests:

tasks.named("test").configure {
	systemProperty "spring.aot.enabled", "true"
}

@wilkinsona
Copy link
Member

This is, at least in part, a Framework bug. I've opened spring-projects/spring-framework#29385. Let's keep this issue open for now to check that things work once the problem in Framework has been corrected. There's some reflection in JsonTesterFactoryBean that may fail but isn't being called yet.

@wilkinsona wilkinsona added the status: blocked An issue that's blocked on an external project change label Oct 26, 2022
@wilkinsona wilkinsona modified the milestones: 3.0.0-RC2, 3.0.x Nov 8, 2022
@wilkinsona wilkinsona added status: blocked An issue that's blocked on an external project change and removed status: blocked An issue that's blocked on an external project change labels Nov 8, 2022
@wilkinsona
Copy link
Member

With the latest Framework changes, AOT-processed tests now pass. Native tests fail with an error like this:

  JUnit Jupiter:JsonApplicationTests:deserializeDto3()
    MethodSource [className = 'com.example.json.JsonApplicationTests', methodName = 'deserializeDto3', methodParameterTypes = '']
    => org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'null': Unsatisfied dependency expressed through field 'dtoTester': Error creating bean with name 'jacksonTesterFactoryBean': FactoryBean threw exception on object creation
       org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.resolveFieldValue(AutowiredAnnotationBeanPostProcessor.java:744)
       org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:724)
       org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:127)
       org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.processInjection(AutowiredAnnotationBeanPostProcessor.java:506)
       org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependenciesInAotMode(DependencyInjectionTestExecutionListener.java:159)
       [...]
     Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jacksonTesterFactoryBean': FactoryBean threw exception on object creation
       org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:154)
       org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBean(FactoryBeanRegistrySupport.java:124)
       org.springframework.beans.factory.support.AbstractBeanFactory.getObjectForBeanInstance(AbstractBeanFactory.java:1823)
       org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getObjectForBeanInstance(AbstractAutowireCapableBeanFactory.java:1265)
       org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:349)
       [...]
     Caused by: java.lang.IllegalStateException: class org.springframework.boot.test.json.JacksonTester does not have a usable constructor
       org.springframework.boot.test.autoconfigure.json.JsonTestersAutoConfiguration$JsonTesterFactoryBean.getObject(JsonTestersAutoConfiguration.java:152)
       org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:148)
       [...]

@wilkinsona wilkinsona self-assigned this Nov 9, 2022
@wilkinsona wilkinsona changed the title Native image tests: No qualifying bean of type 'JacksonTester' JsonTesters do not work in a native image Nov 9, 2022
@wilkinsona wilkinsona changed the title JsonTesters do not work in a native image JsonTesters do not work in native tests Nov 9, 2022
@wilkinsona wilkinsona modified the milestones: 3.0.x, 3.0.0-RC2 Nov 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
theme: aot An issue related to Ahead-of-time processing type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants