我无法让这个工作。我从一个工作正常的 SpringBoot (v2.2.2) 应用程序和一个工作的 @RestController 开始。为了让 springdoc 工作,我在我的 pom 中包含了以下依赖项:
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.2.28</version>
</dependency>
然后我建立并开始了我的服务。然后我浏览到 api-docs 端点,我得到:
{"openapi":"3.0.1","info":{"title":"OpenAPI definition","version":"v0"},"servers":[{"url":"http://localhost:8081","description":"Generated server url"}],"paths":{},"components":{}}
我错过了一步吗?我假设在运行时它会扫描我的代码,找到@RestController,找到@RequestMapping 方法并从中生成api。
作为第二次尝试,我决定用大张旗鼓的@Operation 注释来注释我的一个方法,但仍然没有得到任何东西。
最后,我尝试使用 springdoc.packagesToScan 手动使用我的控制器指定包,但这也不起作用。
这感觉就像 springdoc 没有看到我的控制器 .. 即使 spring 看到了 .. 它非常活跃并且可以工作..
不知道我错过了什么..
这是我的项目依赖项:
[INFO] +- org.springframework.boot:spring-boot-starter-web:jar:2.2.2.RELEASE:compile
[INFO] | +- org.springframework.boot:spring-boot-starter:jar:2.2.2.RELEASE:compile
[INFO] | | +- org.springframework.boot:spring-boot:jar:2.2.2.RELEASE:compile
[INFO] | | +- org.springframework.boot:spring-boot-autoconfigure:jar:2.2.2.RELEASE:compile
[INFO] | | +- org.springframework.boot:spring-boot-starter-logging:jar:2.2.2.RELEASE:compile
[INFO] | | | +- ch.qos.logback:logback-classic:jar:1.2.3:compile
[INFO] | | | | \- ch.qos.logback:logback-core:jar:1.2.3:compile
[INFO] | | | +- org.apache.logging.log4j:log4j-to-slf4j:jar:2.12.1:compile
[INFO] | | | | \- org.apache.logging.log4j:log4j-api:jar:2.12.1:compile
[INFO] | | | \- org.slf4j:jul-to-slf4j:jar:1.7.29:compile
[INFO] | | +- jakarta.annotation:jakarta.annotation-api:jar:1.3.5:compile
[INFO] | | \- org.yaml:snakeyaml:jar:1.25:compile
[INFO] | +- org.springframework.boot:spring-boot-starter-json:jar:2.2.2.RELEASE:compile
[INFO] | | +- com.fasterxml.jackson.core:jackson-databind:jar:2.10.1:compile
[INFO] | | | +- com.fasterxml.jackson.core:jackson-annotations:jar:2.10.1:compile
[INFO] | | | \- com.fasterxml.jackson.core:jackson-core:jar:2.10.1:compile
[INFO] | | +- com.fasterxml.jackson.datatype:jackson-datatype-jdk8:jar:2.10.1:compile
[INFO] | | +- com.fasterxml.jackson.datatype:jackson-datatype-jsr310:jar:2.10.1:compile
[INFO] | | \- com.fasterxml.jackson.module:jackson-module-parameter-names:jar:2.10.1:compile
[INFO] | +- org.springframework.boot:spring-boot-starter-tomcat:jar:2.2.2.RELEASE:compile
[INFO] | | +- org.apache.tomcat.embed:tomcat-embed-core:jar:9.0.29:compile
[INFO] | | +- org.apache.tomcat.embed:tomcat-embed-el:jar:9.0.29:compile
[INFO] | | \- org.apache.tomcat.embed:tomcat-embed-websocket:jar:9.0.29:compile
[INFO] | +- org.springframework.boot:spring-boot-starter-validation:jar:2.2.2.RELEASE:compile
[INFO] | | +- jakarta.validation:jakarta.validation-api:jar:2.0.1:compile
[INFO] | | \- org.hibernate.validator:hibernate-validator:jar:6.0.18.Final:compile
[INFO] | | +- org.jboss.logging:jboss-logging:jar:3.4.1.Final:compile
[INFO] | | \- com.fasterxml:classmate:jar:1.5.1:compile
[INFO] | +- org.springframework:spring-web:jar:5.2.2.RELEASE:compile
[INFO] | | \- org.springframework:spring-beans:jar:5.2.2.RELEASE:compile
[INFO] | \- org.springframework:spring-webmvc:jar:5.2.2.RELEASE:compile
[INFO] | +- org.springframework:spring-aop:jar:5.2.2.RELEASE:compile
[INFO] | +- org.springframework:spring-context:jar:5.2.2.RELEASE:compile
[INFO] | \- org.springframework:spring-expression:jar:5.2.2.RELEASE:compile
[INFO] +- com.google.guava:guava:jar:28.1-jre:compile
[INFO] | +- com.google.guava:failureaccess:jar:1.0.1:compile
[INFO] | +- com.google.guava:listenablefuture:jar:9999.0-empty-to-avoid-conflict-with-guava:compile
[INFO] | +- com.google.code.findbugs:jsr305:jar:3.0.2:compile
[INFO] | +- org.checkerframework:checker-qual:jar:2.8.1:compile
[INFO] | +- com.google.errorprone:error_prone_annotations:jar:2.3.2:compile
[INFO] | +- com.google.j2objc:j2objc-annotations:jar:1.3:compile
[INFO] | \- org.codehaus.mojo:animal-sniffer-annotations:jar:1.18:compile
[INFO] +- org.apache.commons:commons-lang3:jar:3.9:compile
[INFO] +- org.springdoc:springdoc-openapi-ui:jar:1.2.28:compile
[INFO] | +- org.springdoc:springdoc-openapi-webmvc-core:jar:1.2.28:compile
[INFO] | | \- org.springdoc:springdoc-openapi-common:jar:1.2.28:compile
[INFO] | | +- io.swagger.core.v3:swagger-models:jar:2.1.1:compile
[INFO] | | +- io.swagger.core.v3:swagger-annotations:jar:2.1.1:compile
[INFO] | | \- io.swagger.core.v3:swagger-integration:jar:2.1.1:compile
[INFO] | | \- io.swagger.core.v3:swagger-core:jar:2.1.1:compile
[INFO] | | +- javax.xml.bind:jaxb-api:jar:2.3.1:compile
[INFO] | | | \- javax.activation:javax.activation-api:jar:1.2.0:compile
[INFO] | | +- com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:jar:2.10.1:compile
[INFO] | | \- javax.validation:validation-api:jar:2.0.1.Final:compile
[INFO] | +- org.webjars:swagger-ui:jar:3.24.3:compile
[INFO] | \- org.webjars:webjars-locator:jar:0.38:compile
[INFO] | \- org.webjars:webjars-locator-core:jar:0.41:compile
[INFO] | +- io.github.classgraph:classgraph:jar:4.8.44:compile
[INFO] | \- org.webjars.npm:angular__http:jar:2.4.10:compile
[INFO] +- org.assertj:assertj-core:jar:3.14.0:test
[INFO] \- org.springframework.boot:spring-boot-starter-test:jar:2.2.2.RELEASE:test
[INFO] +- org.springframework.boot:spring-boot-test:jar:2.2.2.RELEASE:test
[INFO] +- org.springframework.boot:spring-boot-test-autoconfigure:jar:2.2.2.RELEASE:test
[INFO] +- com.jayway.jsonpath:json-path:jar:2.4.0:test
[INFO] | +- net.minidev:json-smart:jar:2.3:test
[INFO] | | \- net.minidev:accessors-smart:jar:1.2:test
[INFO] | | \- org.ow2.asm:asm:jar:5.0.4:test
[INFO] | \- org.slf4j:slf4j-api:jar:1.7.29:compile
[INFO] +- jakarta.xml.bind:jakarta.xml.bind-api:jar:2.3.2:test
[INFO] | \- jakarta.activation:jakarta.activation-api:jar:1.2.1:test
[INFO] +- org.junit.jupiter:junit-jupiter:jar:5.5.2:test
[INFO] | +- org.junit.jupiter:junit-jupiter-api:jar:5.5.2:test
[INFO] | | +- org.opentest4j:opentest4j:jar:1.2.0:test
[INFO] | | \- org.junit.platform:junit-platform-commons:jar:1.5.2:test
[INFO] | +- org.junit.jupiter:junit-jupiter-params:jar:5.5.2:test
[INFO] | \- org.junit.jupiter:junit-jupiter-engine:jar:5.5.2:test
[INFO] +- org.junit.vintage:junit-vintage-engine:jar:5.5.2:test
[INFO] | +- org.apiguardian:apiguardian-api:jar:1.1.0:test
[INFO] | +- org.junit.platform:junit-platform-engine:jar:1.5.2:test
[INFO] | \- junit:junit:jar:4.12:test
[INFO] +- org.mockito:mockito-junit-jupiter:jar:3.1.0:test
[INFO] +- org.hamcrest:hamcrest:jar:2.1:test
[INFO] +- org.mockito:mockito-core:jar:3.1.0:test
[INFO] | +- net.bytebuddy:byte-buddy:jar:1.10.4:test
[INFO] | +- net.bytebuddy:byte-buddy-agent:jar:1.10.4:test
[INFO] | \- org.objenesis:objenesis:jar:2.6:test
[INFO] +- org.skyscreamer:jsonassert:jar:1.5.0:test
[INFO] | \- com.vaadin.external.google:android-json:jar:0.0.20131108.vaadin1:test
[INFO] +- org.springframework:spring-core:jar:5.2.2.RELEASE:compile
[INFO] | \- org.springframework:spring-jcl:jar:5.2.2.RELEASE:compile
[INFO] +- org.springframework:spring-test:jar:5.2.2.RELEASE:test
[INFO] \- org.xmlunit:xmlunit-core:jar:2.6.3:test
这是我项目的树..它是标准的 Spring Boot 结构.. Controller 位于 web dir/package 下
.
├── java
│ └── com
│ └── neodem
│ └── orl
│ ├── collections
│ ├── config
│ ├── engine
│ │ ├── core
│ │ │ ├── actions
│ │ │ └── model
│ │ └── original
│ │ ├── actions
│ │ └── model
│ ├── service
│ └── web
└── resources