Skip to content
This repository was archived by the owner on Feb 23, 2023. It is now read-only.

ClassNotFoundException on springfox while running native image on docker #635

Closed
cipley opened this issue Mar 19, 2021 · 2 comments
Closed
Assignees
Labels
type: question A question

Comments

@cipley
Copy link

cipley commented Mar 19, 2021

Hi,

I am currently trying my hands on Spring Boot native 2.4.3 and managed to compile my project into native docker image.
I used mvn spring-boot:build-image
However, when trying to run it, I got the following error:

java.lang.IllegalArgumentException: Could not find class [springfox.documentation.spi.schema.ModelBuilderPlugin]
        at org.springframework.util.ClassUtils.resolveClassName(ClassUtils.java:334) ~[na:na]
        at org.springframework.core.annotation.TypeMappedAnnotation.adapt(TypeMappedAnnotation.java:446) ~[na:na]
        at org.springframework.core.annotation.TypeMappedAnnotation.getValue(TypeMappedAnnotation.java:369) ~[na:na]
        at org.springframework.core.annotation.TypeMappedAnnotation.asMap(TypeMappedAnnotation.java:284) ~[na:na]
        at org.springframework.core.annotation.AbstractMergedAnnotation.asAnnotationAttributes(AbstractMergedAnnotation.java:193) ~[na:na]
        at org.springframework.core.type.AnnotatedTypeMetadata.getAnnotationAttributes(AnnotatedTypeMetadata.java:106) ~[na:na]
        at org.springframework.context.annotation.AnnotationConfigUtils.attributesFor(AnnotationConfigUtils.java:285) ~[na:na]
        at org.springframework.context.annotation.AnnotationBeanNameGenerator.determineBeanNameFromAnnotation(AnnotationBeanNameGenerator.java:102) ~[na:na]
        at org.springframework.context.annotation.AnnotationBeanNameGenerator.generateBeanName(AnnotationBeanNameGenerator.java:81) ~[na:na]
        at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.registerBeanDefinitionForImportedConfigurationClass(ConfigurationClassBeanDefinitionReader.java:169) ~[na:na]
        at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForConfigurationClass(ConfigurationClassBeanDefinitionReader.java:150) ~[na:na]
        at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitions(ConfigurationClassBeanDefinitionReader.java:129) ~[na:na]
        at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:348) ~[id.co.telkomsel.digitalcore.bs.networkprofile.api.Application:5.3.1]
        at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:252) ~[id.co.telkomsel.digitalcore.bs.networkprofile.api.Application:5.3.1]
        at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:285) ~[na:na]
        at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:99) ~[na:na]
        at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:751) ~[na:na]
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:569) ~[na:na]
        at org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext.refresh(ReactiveWebServerApplicationContext.java:63) ~[na:na]
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:767) [id.co.telkomsel.digitalcore.bs.networkprofile.api.Application:na]
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759) [id.co.telkomsel.digitalcore.bs.networkprofile.api.Application:na]
        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:426) [id.co.telkomsel.digitalcore.bs.networkprofile.api.Application:na]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:326) [id.co.telkomsel.digitalcore.bs.networkprofile.api.Application:na]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1311) [id.co.telkomsel.digitalcore.bs.networkprofile.api.Application:na]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1300) [id.co.telkomsel.digitalcore.bs.networkprofile.api.Application:na]
        at id.co.telkomsel.digitalcore.bs.networkprofile.api.Application.main(Application.java:18) [id.co.telkomsel.digitalcore.bs.networkprofile.api.Application:na]
Caused by: java.lang.ClassNotFoundException: springfox.documentation.spi.schema.ModelBuilderPlugin
        at com.oracle.svm.core.hub.ClassForNameSupport.forName(ClassForNameSupport.java:60) ~[na:na]
        at java.lang.Class.forName(DynamicHub.java:1260) ~[na:na]
        at org.springframework.util.ClassUtils.forName(ClassUtils.java:284) ~[na:na]
        at org.springframework.util.ClassUtils.resolveClassName(ClassUtils.java:324) ~[na:na]
        ... 25 common frames omitted

Below is my springfox dependencies: (I am using version 3.0.0)

...
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>${springfox.version}</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>${springfox.version}</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-boot-starter</artifactId>
            <version>${springfox.version}</version>
        </dependency>
...

I have already tried adding springfox.documentation.spi.schema.ModelBuilderPlugin and other sprongfox classes as well to my reflection-config.json, to no avail.

Is there anything that I could have missed?

@sdeleuze sdeleuze added the type: question A question label Mar 19, 2021
@sdeleuze sdeleuze self-assigned this Mar 19, 2021
@sdeleuze
Copy link
Contributor

Not sure what happens here, but I can suggest to use native hints annotations to add reflection configuration. This will allow to have static typing checks and will make the generated config part of what Spring AOT generates. Here with the default access bits it should work, check in the generated config in target/generated-sources/spring-aot/src/main/sources/META-INF/native-image if you see the related entries.

Also notice I am not sure how much native configuration Spring Fox will require, and that this will likley not be provided on Sprign Native side.

Please let me know how it goes.

@sdeleuze
Copy link
Contributor

Closing due to lack of response.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: question A question
Development

No branches or pull requests

2 participants