简体   繁体   English

Spring-boot swagger 在 io.swagger.models.parameters.Parameter 上抛出 java.lang.ClassNotFoundException

[英]Spring-boot swagger throws java.lang.ClassNotFoundException on io.swagger.models.parameters.Parameter

I am using the following spring-boot dependencies in order to generate a swagger file for my Spring-boot application:我正在使用以下 spring-boot 依赖项来为我的Spring-boot应用程序生成一个 swagger 文件:

<dependency>
    <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>${swagger-fox.version}</version>
            <exclusions>
                <exclusion>
                    <artifactId>swagger-annotations</artifactId>
                    <groupId>io.swagger</groupId>
            </exclusion>
            <exclusion>
                <artifactId>swagger-models</artifactId>
                <groupId>io.swagger</groupId>
            </exclusion>
        </exclusions>
</dependency>
<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger-ui</artifactId>
    <version>${swagger-fox.version}</version>
</dependency>

<properties>
        <swagger.version>1.6.0</swagger.version>
        <java.version>11</java.version>
        <dockerfile-maven-version>1.4.3</dockerfile-maven-version>
        <swagger-fox.version>2.9.2</swagger-fox.version>
</properties>

And this is the swagger configuration class, which I have included in my app:这是我在我的应用程序中包含的 swagger 配置 class:


@SpringBootApplication
@EnableSwagger2
public class SpringFoxConfig {


    private static final String AUTHOR_MAIL = "xxx@xxx.com";

    private static final String API_TITLE = "DEMO  Service REST API";

    private static final String API_DESCRIPTION = "demo";

    private static final String API_BASE_PACKAGE = "demo_package";


    private ApiInfo getApiInfo() {
        return new ApiInfo(API_TITLE, API_DESCRIPTION, "V1", "", AUTHOR_MAIL,
                "","");
    }

    @Bean
    public Docket api() {
        return new Docket(DocumentationType.SWAGGER_2).apiInfo(getApiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage(API_BASE_PACKAGE))
                .paths(PathSelectors.any())
                .build();
    }

Despite that when I run my app I get the following error:尽管如此,当我运行我的应用程序时,我收到以下错误:


java.lang.NoClassDefFoundError: io/swagger/models/parameters/Parameter
    at java.base/java.lang.Class.getDeclaredConstructors0(Native Method) ~[na:na]
    at java.base/java.lang.Class.privateGetDeclaredConstructors(Class.java:3137) ~[na:na]
    at java.base/java.lang.Class.getDeclaredConstructors(Class.java:2357) ~[na:na]
    at org.springframework.boot.context.properties.ConfigurationPropertiesBindConstructorProvider.findConstructorBindingAnnotatedConstructor(ConfigurationPropertiesBindConstructorProvider.java:62) ~[spring-boot-2.2.4.RELEASE.jar:2.2.4.RELEASE]
    at org.springframework.boot.context.properties.ConfigurationPropertiesBindConstructorProvider.getBindConstructor(ConfigurationPropertiesBindConstructorProvider.java:48) ~[spring-boot-2.2.4.RELEASE.jar:2.2.4.RELEASE]
    at org.springframework.boot.context.properties.ConfigurationPropertiesBean$BindMethod.forType(ConfigurationPropertiesBean.java:311) ~[spring-boot-2.2.4.RELEASE.jar:2.2.4.RELEASE]
    at org.springframework.boot.context.properties.ConfigurationPropertiesBeanDefinitionValidator.validate(ConfigurationPropertiesBeanDefinitionValidator.java:63) ~[spring-boot-2.2.4.RELEASE.jar:2.2.4.RELEASE]
    at org.springframework.boot.context.properties.ConfigurationPropertiesBeanDefinitionValidator.postProcessBeanFactory(ConfigurationPropertiesBeanDefinitionValidator.java:45) ~[spring-boot-2.2.4.RELEASE.jar:2.2.4.RELEASE]
    at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:286) ~[spring-context-5.2.3.RELEASE.jar:5.2.3.RELEASE]
    at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:174) ~[spring-context-5.2.3.RELEASE.jar:5.2.3.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:706) ~[spring-context-5.2.3.RELEASE.jar:5.2.3.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) ~[spring-context-5.2.3.RELEASE.jar:5.2.3.RELEASE]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141) ~[spring-boot-2.2.4.RELEASE.jar:2.2.4.RELEASE]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747) ~[spring-boot-2.2.4.RELEASE.jar:2.2.4.RELEASE]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) ~[spring-boot-2.2.4.RELEASE.jar:2.2.4.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) ~[spring-boot-2.2.4.RELEASE.jar:2.2.4.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) ~[spring-boot-2.2.4.RELEASE.jar:2.2.4.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215) ~[spring-boot-2.2.4.RELEASE.jar:2.2.4.RELEASE]
    at demo.Application.main(Application.java:10) ~[classes/:na]
Caused by: java.lang.ClassNotFoundException: io.swagger.models.parameters.Parameter
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581) ~[na:na]
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178) ~[na:na]
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521) ~[na:na]
    ... 19 common frames omitted

Note that I also get a warning that the method ApiInfo is deprecated and suspect that error has something to do with it, however I am not sure about it.请注意,我还收到一条警告,指出ApiInfo方法已被弃用,并怀疑错误与此有关,但我不确定。 Could anyone help me figure out how to go about solving this?谁能帮我弄清楚如何解决这个问题 go? Thanks in advance提前致谢

Interface Parameter is from the swagger-models maven dependency.接口参数来自swagger-models maven 依赖项。

To fix the issue simply remove the corresponding exclusion from the POM file:要解决此问题,只需从 POM 文件中删除相应的排除项:

<exclusion>
  <artifactId>swagger-models</artifactId>
  <groupId>io.swagger</groupId>
</exclusion>

Swagger is not working properly in spring boot version 2.2.0 an above. Swagger 在 Spring Boot 2.2.0 及以上版本中无法正常工作。 You can use alternatively您可以交替使用

"springdoc-openapi-ui" “springdoc-openapi-ui”

Tutorial available at www.baeldung.com/spring-rest-openapi-documentation教程可在www.baeldung.com/spring-rest-openapi-documentation

<!-- https://mvnrepository.com/artifact/org.springdoc/springdoc-openapi-ui -->
<dependency>
    <groupId>org.springdoc</groupId>
    <artifactId>springdoc-openapi-ui</artifactId>
    <version>1.2.30</version>
</dependency>

I could resolve my issue when I downgraded my version to 1.6.4 from 1.6.9当我将版本从 1.6.9 降级到 1.6.4 时,我可以解决我的问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 春季启动Reactor java.lang.ClassNotFoundException MultiReaderFastList - spring-boot Reactor java.lang.ClassNotFoundException MultiReaderFastList Hazelcast Spring Boot java.lang.ClassNotFoundException - Hazelcast Spring Boot java.lang.ClassNotFoundException 春季启动java.lang.ClassNotFoundException:org.dom4j.io.STAXEventReader - spring boot java.lang.ClassNotFoundException: org.dom4j.io.STAXEventReader RabbitMq和Spring Boot 1.5.8错误java.lang.ClassNotFoundException:react.io.codec.Codec - RabbitMq and Spring Boot 1.5.8 error java.lang.ClassNotFoundException: reactor.io.codec.Codec spring boot和maven build上的java.lang.ClassNotFoundException - java.lang.ClassNotFoundException on spring boot and maven build Spring Boot 2升级java.lang.ClassNotFoundException:EmbeddedServletContainerCustomizer - Spring Boot 2 upgrade java.lang.ClassNotFoundException: EmbeddedServletContainerCustomizer java - 版本抛出“java.lang.ClassNotFoundException:” - java -version throws "java.lang.ClassNotFoundException: " Spring Boot可执行jar引发java.lang.ClassNotFoundException:org.apache.tomcat.util.descriptor.web.ServletDef - Spring Boot executable jar throws java.lang.ClassNotFoundException: org.apache.tomcat.util.descriptor.web.ServletDef 如何将 swagger 与球衣 + spring-boot 结合起来 - How to integrate swagger with jersey + spring-boot spring-boot:run抛出ClassNotFoundException - spring-boot:run throws ClassNotFoundException
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM