Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring 缺少Swagger 2 UI资源映射和API文档_Spring_Spring Boot_Swagger_Swagger Ui_Springfox - Fatal编程技术网

Spring 缺少Swagger 2 UI资源映射和API文档

Spring 缺少Swagger 2 UI资源映射和API文档,spring,spring-boot,swagger,swagger-ui,springfox,Spring,Spring Boot,Swagger,Swagger Ui,Springfox,这是一个springboot项目。 我已经在我的.pom文件中添加了SpringFox,这是一个基于Swagger 2的API文档工具 配置它,但出于某种原因(我猜资源映射工作不正常) 配置的基本部分在那里,但当我添加了更具体的配置时, 如我的联系方式或API描述->此部分不显示 这是我的招摇过市配置类: @Component @PropertySource("classpath:springFoxdocumentation.yml") @EnableSwagger2 @En

这是一个springboot项目。 我已经在我的.pom文件中添加了SpringFox,这是一个基于Swagger 2的API文档工具 配置它,但出于某种原因(我猜资源映射工作不正常) 配置的基本部分在那里,但当我添加了更具体的配置时, 如我的联系方式或API描述->此部分不显示

这是我的招摇过市配置类:

@Component
@PropertySource("classpath:springFoxdocumentation.yml")
@EnableSwagger2
@EnableWebMvc
public class SpringFoxConfig implements WebMvcConfigurer  {

    @Value("${api.common.version}")
    private static String apiVersion;
    @Value("${api.common.title}")
    private static String apiTitle;
    @Value("${api.common.description}")
    private static String apiDescription;
    @Value("${api.common.termsOfServiceUrl}")
    private static String apiTermsOfServiceUrl;
    @Value("${api.common.license}")
    private static String apiLicense;
    @Value("${api.common.licenseUrl}")
    private static String apiLicenseUrl;
    @Value("${api.common.contact.name}")
    private static String apiContactName;
    @Value("${api.common.contact.url}")
    private static String apiContactUrl;
    @Value("${api.common.contact.email}")
    private static String apiContactEmail;



    @Bean
    public Docket apiDocumentation(){
        return new Docket(DocumentationType.SWAGGER_2)
                .select()
                .apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.any())
                .build()
                    .globalResponseMessage(RequestMethod.GET, Collections.emptyList())
                    .apiInfo(new ApiInfo(
                        apiVersion,
                        apiTitle,
                        apiDescription,
                        apiTermsOfServiceUrl,
                        new Contact( apiContactName, apiContactUrl,apiContactEmail),
                        apiLicense,
                        apiLicenseUrl,
                        Collections.emptyList()
                    ));
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("swagger-ui.html")
                .addResourceLocations("classpath:/META-INF/resources/");

        registry.addResourceHandler("/webjars/**")
                .addResourceLocations("classpath:/META-INF/resources/webjars/");
    }

}
我知道我不应该有ResourceHandler方法,但是因为我假设这个问题是由ResourceMapper引起的,所以我在代码中添加了它(但是没有帮助)

这是我在resources文件夹下的.yml文件

api:
  common:
    version: 1.0.0
    title: Ticket Manager
    description: Ticket Manager server as a simple REST API for managing ticket and Incidents
    termsOfServiceUrl: LINK FOR TERMS OF SERVICE
    license: This is a Open Source Licensed product
    licenseUrl: LINK FOR LICENSE URL
    contact:
      name: opensourcedev
      url: URL FOR OPENSOURCEDEV
      email: sample@gmail.com
最后,这是我启动Swagger 2 html页面时应用程序中的日志http://localhost:8080/swagger-ui.html#/

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.3.3.RELEASE)

2020-10-18 18:26:36.651  INFO 14928 --- [           main] c.o.t.TicketManagerApplication           : Starting TicketManagerApplication on DESKTOP-FJ83RN4 with PID 14928 (D:\Git Projects\ticket-manager\target\classes started by sajmo in D:\Git Projects\ticket-manager)
2020-10-18 18:26:36.653  INFO 14928 --- [           main] c.o.t.TicketManagerApplication           : No active profile set, falling back to default profiles: default
2020-10-18 18:26:37.378  INFO 14928 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFERRED mode.
2020-10-18 18:26:37.436  INFO 14928 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 51ms. Found 3 JPA repository interfaces.
2020-10-18 18:26:37.832  INFO 14928 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2020-10-18 18:26:37.840  INFO 14928 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2020-10-18 18:26:37.840  INFO 14928 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.37]
2020-10-18 18:26:37.962  INFO 14928 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2020-10-18 18:26:37.962  INFO 14928 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1258 ms
2020-10-18 18:26:38.063  INFO 14928 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
2020-10-18 18:26:38.087  INFO 14928 --- [           main] f.a.AutowiredAnnotationBeanPostProcessor : Autowired annotation is not supported on static fields: private static java.lang.String com.opensourcedev.ticketmanager.apidocs.SpringFoxConfig.apiVersion
2020-10-18 18:26:38.088  INFO 14928 --- [           main] f.a.AutowiredAnnotationBeanPostProcessor : Autowired annotation is not supported on static fields: private static java.lang.String com.opensourcedev.ticketmanager.apidocs.SpringFoxConfig.apiTitle
2020-10-18 18:26:38.088  INFO 14928 --- [           main] f.a.AutowiredAnnotationBeanPostProcessor : Autowired annotation is not supported on static fields: private static java.lang.String com.opensourcedev.ticketmanager.apidocs.SpringFoxConfig.apiDescription
2020-10-18 18:26:38.088  INFO 14928 --- [           main] f.a.AutowiredAnnotationBeanPostProcessor : Autowired annotation is not supported on static fields: private static java.lang.String com.opensourcedev.ticketmanager.apidocs.SpringFoxConfig.apiTermsOfServiceUrl
2020-10-18 18:26:38.088  INFO 14928 --- [           main] f.a.AutowiredAnnotationBeanPostProcessor : Autowired annotation is not supported on static fields: private static java.lang.String com.opensourcedev.ticketmanager.apidocs.SpringFoxConfig.apiLicense
2020-10-18 18:26:38.088  INFO 14928 --- [           main] f.a.AutowiredAnnotationBeanPostProcessor : Autowired annotation is not supported on static fields: private static java.lang.String com.opensourcedev.ticketmanager.apidocs.SpringFoxConfig.apiLicenseUrl
2020-10-18 18:26:38.088  INFO 14928 --- [           main] f.a.AutowiredAnnotationBeanPostProcessor : Autowired annotation is not supported on static fields: private static java.lang.String com.opensourcedev.ticketmanager.apidocs.SpringFoxConfig.apiContactName
2020-10-18 18:26:38.088  INFO 14928 --- [           main] f.a.AutowiredAnnotationBeanPostProcessor : Autowired annotation is not supported on static fields: private static java.lang.String com.opensourcedev.ticketmanager.apidocs.SpringFoxConfig.apiContactUrl
2020-10-18 18:26:38.088  INFO 14928 --- [           main] f.a.AutowiredAnnotationBeanPostProcessor : Autowired annotation is not supported on static fields: private static java.lang.String com.opensourcedev.ticketmanager.apidocs.SpringFoxConfig.apiContactEmail
2020-10-18 18:26:38.246  WARN 14928 --- [           main] JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
2020-10-18 18:26:38.273  INFO 14928 --- [         task-1] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
2020-10-18 18:26:38.303 DEBUG 14928 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : 17 mappings in 'requestMappingHandlerMapping'
2020-10-18 18:26:38.353  INFO 14928 --- [           main] pertySourcedRequestMappingHandlerMapping : Mapped URL path [/v2/api-docs] onto method [springfox.documentation.swagger2.web.Swagger2Controller#getDocumentation(String, HttpServletRequest)]
2020-10-18 18:26:38.373 DEBUG 14928 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Patterns [/swagger-ui.html, /webjars/**] in 'resourceHandlerMapping'
2020-10-18 18:26:38.427 DEBUG 14928 --- [           main] s.w.s.m.m.a.RequestMappingHandlerAdapter : ControllerAdvice beans: 0 @ModelAttribute, 0 @InitBinder, 1 RequestBodyAdvice, 1 ResponseBodyAdvice
2020-10-18 18:26:38.448 DEBUG 14928 --- [           main] .m.m.a.ExceptionHandlerExceptionResolver : ControllerAdvice beans: 0 @ExceptionHandler, 1 ResponseBodyAdvice
2020-10-18 18:26:38.567  INFO 14928 --- [         task-1] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.
2020-10-18 18:26:38.587  INFO 14928 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2020-10-18 18:26:38.588  INFO 14928 --- [           main] d.s.w.p.DocumentationPluginsBootstrapper : Context refreshed
2020-10-18 18:26:38.602  INFO 14928 --- [           main] d.s.w.p.DocumentationPluginsBootstrapper : Found 1 custom documentation plugin(s)
2020-10-18 18:26:38.627  INFO 14928 --- [           main] s.d.s.w.s.ApiListingReferenceScanner     : Scanning for api listing references
2020-10-18 18:26:38.753  INFO 14928 --- [           main] .d.s.w.r.o.CachingOperationNameGenerator : Generating unique operation named: deleteUsingDELETE_1
2020-10-18 18:26:38.770  INFO 14928 --- [           main] .d.s.w.r.o.CachingOperationNameGenerator : Generating unique operation named: findAllTicketsUsingGET_1
2020-10-18 18:26:38.773  INFO 14928 --- [           main] .d.s.w.r.o.CachingOperationNameGenerator : Generating unique operation named: findByIdUsingGET_1
2020-10-18 18:26:38.783  INFO 14928 --- [           main] .d.s.w.r.o.CachingOperationNameGenerator : Generating unique operation named: saveUsingPOST_1
2020-10-18 18:26:38.786  INFO 14928 --- [           main] .d.s.w.r.o.CachingOperationNameGenerator : Generating unique operation named: deleteUsingDELETE_2
2020-10-18 18:26:38.787  INFO 14928 --- [           main] .d.s.w.r.o.CachingOperationNameGenerator : Generating unique operation named: deleteUsingDELETE_3
2020-10-18 18:26:38.791  INFO 14928 --- [           main] .d.s.w.r.o.CachingOperationNameGenerator : Generating unique operation named: findAllTicketsUsingGET_2
2020-10-18 18:26:38.792  INFO 14928 --- [           main] .d.s.w.r.o.CachingOperationNameGenerator : Generating unique operation named: findAllTicketsUsingGET_3
2020-10-18 18:26:38.795  INFO 14928 --- [           main] .d.s.w.r.o.CachingOperationNameGenerator : Generating unique operation named: findbyIdUsingGET_1
2020-10-18 18:26:38.800  INFO 14928 --- [           main] .d.s.w.r.o.CachingOperationNameGenerator : Generating unique operation named: saveUsingPOST_2
2020-10-18 18:26:38.801  INFO 14928 --- [           main] .d.s.w.r.o.CachingOperationNameGenerator : Generating unique operation named: saveUsingPOST_3
2020-10-18 18:26:38.803  INFO 14928 --- [           main] .d.s.w.r.o.CachingOperationNameGenerator : Generating unique operation named: deleteUsingDELETE_4
2020-10-18 18:26:38.804  INFO 14928 --- [           main] .d.s.w.r.o.CachingOperationNameGenerator : Generating unique operation named: deleteUsingDELETE_5
2020-10-18 18:26:38.809  INFO 14928 --- [           main] .d.s.w.r.o.CachingOperationNameGenerator : Generating unique operation named: findAllTicketsUsingGET_4
2020-10-18 18:26:38.809  INFO 14928 --- [           main] .d.s.w.r.o.CachingOperationNameGenerator : Generating unique operation named: findAllTicketsUsingGET_5
2020-10-18 18:26:38.812  INFO 14928 --- [           main] .d.s.w.r.o.CachingOperationNameGenerator : Generating unique operation named: findbyIdUsingGET_2
2020-10-18 18:26:38.813  INFO 14928 --- [           main] .d.s.w.r.o.CachingOperationNameGenerator : Generating unique operation named: findbyIdUsingGET_3
2020-10-18 18:26:38.817  INFO 14928 --- [           main] .d.s.w.r.o.CachingOperationNameGenerator : Generating unique operation named: saveUsingPOST_4
2020-10-18 18:26:38.818  INFO 14928 --- [           main] .d.s.w.r.o.CachingOperationNameGenerator : Generating unique operation named: saveUsingPOST_5
2020-10-18 18:26:38.826  INFO 14928 --- [           main] DeferredRepositoryInitializationListener : Triggering deferred initialization of Spring Data repositories…
2020-10-18 18:26:39.291  INFO 14928 --- [         task-1] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2020-10-18 18:26:39.428  INFO 14928 --- [           main] DeferredRepositoryInitializationListener : Spring Data repositories initialized!
2020-10-18 18:26:39.436  INFO 14928 --- [           main] c.o.t.TicketManagerApplication           : Started TicketManagerApplication in 3.057 seconds (JVM running for 3.892)
2020-10-18 18:26:50.042  INFO 14928 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring DispatcherServlet 'dispatcherServlet'
2020-10-18 18:26:50.042  INFO 14928 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Initializing Servlet 'dispatcherServlet'
2020-10-18 18:26:50.042 DEBUG 14928 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Detected StandardServletMultipartResolver
2020-10-18 18:26:50.047 DEBUG 14928 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : enableLoggingRequestDetails='false': request parameters and headers will be masked to prevent unsafe logging of potentially sensitive data
2020-10-18 18:26:50.047  INFO 14928 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Completed initialization in 5 ms
2020-10-18 18:26:50.053 DEBUG 14928 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : GET "/v2/api-docs", parameters={}
2020-10-18 18:26:50.168 DEBUG 14928 --- [nio-8080-exec-1] o.s.w.s.m.m.a.HttpEntityMethodProcessor  : Using 'application/json;q=0.8', given [text/html, application/xhtml+xml, image/avif, image/webp, image/apng, application/xml;q=0.9, application/signed-exchange;v=b3;q=0.9, */*;q=0.8] and supported [application/json, application/*+json]
2020-10-18 18:26:50.169 DEBUG 14928 --- [nio-8080-exec-1] o.s.w.s.m.m.a.HttpEntityMethodProcessor  : Writing [springfox.documentation.spring.web.json.Json@51a025e9]
2020-10-18 18:26:50.178 DEBUG 14928 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Completed 200 OK
2020-10-18 18:27:24.254 DEBUG 14928 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet        : GET "/swagger-ui.html", parameters={}
2020-10-18 18:27:24.257 DEBUG 14928 --- [nio-8080-exec-2] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped to ResourceHttpRequestHandler ["classpath:/META-INF/resources/"]
2020-10-18 18:27:24.262 DEBUG 14928 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet        : Completed 304 NOT_MODIFIED
2020-10-18 18:27:24.391 DEBUG 14928 --- [nio-8080-exec-3] o.s.web.servlet.DispatcherServlet        : GET "/swagger-resources/configuration/ui", parameters={}
2020-10-18 18:27:24.392 DEBUG 14928 --- [nio-8080-exec-3] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped to springfox.documentation.swagger.web.ApiResourceController#uiConfiguration()
2020-10-18 18:27:24.393 DEBUG 14928 --- [nio-8080-exec-4] o.s.web.servlet.DispatcherServlet        : GET "/webjars/springfox-swagger-ui/favicon-32x32.png?v=2.9.2", parameters={masked}
2020-10-18 18:27:24.394 DEBUG 14928 --- [nio-8080-exec-4] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped to ResourceHttpRequestHandler ["classpath:/META-INF/resources/webjars/"]
2020-10-18 18:27:24.397 DEBUG 14928 --- [nio-8080-exec-4] o.s.web.servlet.DispatcherServlet        : Completed 200 OK
2020-10-18 18:27:24.398 DEBUG 14928 --- [nio-8080-exec-3] o.s.w.s.m.m.a.HttpEntityMethodProcessor  : Using 'application/json', given [application/json] and supported [application/json, application/*+json]
2020-10-18 18:27:24.398 DEBUG 14928 --- [nio-8080-exec-3] o.s.w.s.m.m.a.HttpEntityMethodProcessor  : Writing [springfox.documentation.swagger.web.UiConfiguration@674d67e1]
2020-10-18 18:27:24.400 DEBUG 14928 --- [nio-8080-exec-3] o.s.web.servlet.DispatcherServlet        : Completed 200 OK
2020-10-18 18:27:24.404 DEBUG 14928 --- [nio-8080-exec-5] o.s.web.servlet.DispatcherServlet        : GET "/swagger-resources/configuration/security", parameters={}
2020-10-18 18:27:24.404 DEBUG 14928 --- [nio-8080-exec-5] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped to springfox.documentation.swagger.web.ApiResourceController#securityConfiguration()
2020-10-18 18:27:24.406 DEBUG 14928 --- [nio-8080-exec-5] o.s.w.s.m.m.a.HttpEntityMethodProcessor  : Using 'application/json', given [application/json] and supported [application/json, application/*+json]
2020-10-18 18:27:24.406 DEBUG 14928 --- [nio-8080-exec-5] o.s.w.s.m.m.a.HttpEntityMethodProcessor  : Writing [springfox.documentation.swagger.web.SecurityConfiguration@466a47c4]
2020-10-18 18:27:24.407 DEBUG 14928 --- [nio-8080-exec-5] o.s.web.servlet.DispatcherServlet        : Completed 200 OK
2020-10-18 18:27:24.410 DEBUG 14928 --- [nio-8080-exec-6] o.s.web.servlet.DispatcherServlet        : GET "/swagger-resources", parameters={}
2020-10-18 18:27:24.410 DEBUG 14928 --- [nio-8080-exec-6] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped to springfox.documentation.swagger.web.ApiResourceController#swaggerResources()
2020-10-18 18:27:24.411 DEBUG 14928 --- [nio-8080-exec-6] o.s.w.s.m.m.a.HttpEntityMethodProcessor  : Using 'application/json', given [application/json] and supported [application/json, application/*+json]
2020-10-18 18:27:24.411 DEBUG 14928 --- [nio-8080-exec-6] o.s.w.s.m.m.a.HttpEntityMethodProcessor  : Writing [[springfox.documentation.swagger.web.SwaggerResource@592c2c2f]]
2020-10-18 18:27:24.413 DEBUG 14928 --- [nio-8080-exec-6] o.s.web.servlet.DispatcherServlet        : Completed 200 OK
2020-10-18 18:27:24.445 DEBUG 14928 --- [nio-8080-exec-8] o.s.web.servlet.DispatcherServlet        : GET "/", parameters={}
2020-10-18 18:27:24.445 DEBUG 14928 --- [nio-8080-exec-7] o.s.web.servlet.DispatcherServlet        : GET "/v2/api-docs", parameters={}
2020-10-18 18:27:24.446  WARN 14928 --- [nio-8080-exec-8] o.s.web.servlet.PageNotFound             : No mapping for GET /
2020-10-18 18:27:24.446 DEBUG 14928 --- [nio-8080-exec-8] o.s.web.servlet.DispatcherServlet        : Completed 404 NOT_FOUND
2020-10-18 18:27:24.449 DEBUG 14928 --- [nio-8080-exec-8] o.s.web.servlet.DispatcherServlet        : "ERROR" dispatch for GET "/error", parameters={}
2020-10-18 18:27:24.450 DEBUG 14928 --- [nio-8080-exec-8] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped to org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController#error(HttpServletRequest)
2020-10-18 18:27:24.452 DEBUG 14928 --- [nio-8080-exec-8] o.s.w.s.m.m.a.HttpEntityMethodProcessor  : Using 'application/json', given [*/*] and supported [application/json, application/*+json]
2020-10-18 18:27:24.453 DEBUG 14928 --- [nio-8080-exec-8] o.s.w.s.m.m.a.HttpEntityMethodProcessor  : Writing [{timestamp=Sun Oct 18 18:27:24 CEST 2020, status=404, error=Not Found, message=, path=/}]
2020-10-18 18:27:24.454 DEBUG 14928 --- [nio-8080-exec-8] o.s.web.servlet.DispatcherServlet        : Exiting from "ERROR" dispatch, status 404
2020-10-18 18:27:24.458 DEBUG 14928 --- [nio-8080-exec-9] o.s.web.servlet.DispatcherServlet        : GET "/csrf", parameters={}
2020-10-18 18:27:24.458 DEBUG 14928 --- [nio-8080-exec-7] o.s.w.s.m.m.a.HttpEntityMethodProcessor  : Using 'application/json', given [application/json, */*] and supported [application/json, application/*+json]
2020-10-18 18:27:24.458 DEBUG 14928 --- [nio-8080-exec-7] o.s.w.s.m.m.a.HttpEntityMethodProcessor  : Writing [springfox.documentation.spring.web.json.Json@784dbf0b]
2020-10-18 18:27:24.458  WARN 14928 --- [nio-8080-exec-9] o.s.web.servlet.PageNotFound             : No mapping for GET /csrf
2020-10-18 18:27:24.458 DEBUG 14928 --- [nio-8080-exec-9] o.s.web.servlet.DispatcherServlet        : Completed 404 NOT_FOUND
2020-10-18 18:27:24.458 DEBUG 14928 --- [nio-8080-exec-9] o.s.web.servlet.DispatcherServlet        : "ERROR" dispatch for GET "/error", parameters={}
2020-10-18 18:27:24.459 DEBUG 14928 --- [nio-8080-exec-9] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped to org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController#error(HttpServletRequest)
2020-10-18 18:27:24.459 DEBUG 14928 --- [nio-8080-exec-7] o.s.web.servlet.DispatcherServlet        : Completed 200 OK
2020-10-18 18:27:24.459 DEBUG 14928 --- [nio-8080-exec-9] o.s.w.s.m.m.a.HttpEntityMethodProcessor  : Using 'application/json', given [*/*] and supported [application/json, application/*+json]
2020-10-18 18:27:24.459 DEBUG 14928 --- [nio-8080-exec-9] o.s.w.s.m.m.a.HttpEntityMethodProcessor  : Writing [{timestamp=Sun Oct 18 18:27:24 CEST 2020, status=404, error=Not Found, message=, path=/csrf}]
2020-10-18 18:27:24.460 DEBUG 14928 --- [nio-8080-exec-9] o.s.web.servlet.DispatcherServlet        : Exiting from "ERROR" dispatch, status 404
2020-10-18 18:29:06.678 DEBUG 14928 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet        : GET "/swagger-resources/configuration/ui", parameters={}
2020-10-18 18:29:06.678 DEBUG 14928 --- [nio-8080-exec-2] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped to springfox.documentation.swagger.web.ApiResourceController#uiConfiguration()
2020-10-18 18:29:06.679 DEBUG 14928 --- [nio-8080-exec-2] o.s.w.s.m.m.a.HttpEntityMethodProcessor  : Using 'application/json', given [application/json] and supported [application/json, application/*+json]
2020-10-18 18:29:06.679 DEBUG 14928 --- [nio-8080-exec-2] o.s.w.s.m.m.a.HttpEntityMethodProcessor  : Writing [springfox.documentation.swagger.web.UiConfiguration@7fcb7c22]
2020-10-18 18:29:06.680 DEBUG 14928 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet        : Completed 200 OK
2020-10-18 18:29:06.684 DEBUG 14928 --- [nio-8080-exec-4] o.s.web.servlet.DispatcherServlet        : GET "/swagger-resources/configuration/security", parameters={}
2020-10-18 18:29:06.684 DEBUG 14928 --- [nio-8080-exec-4] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped to springfox.documentation.swagger.web.ApiResourceController#securityConfiguration()
2020-10-18 18:29:06.685 DEBUG 14928 --- [nio-8080-exec-4] o.s.w.s.m.m.a.HttpEntityMethodProcessor  : Using 'application/json', given [application/json] and supported [application/json, application/*+json]
2020-10-18 18:29:06.685 DEBUG 14928 --- [nio-8080-exec-4] o.s.w.s.m.m.a.HttpEntityMethodProcessor  : Writing [springfox.documentation.swagger.web.SecurityConfiguration@5c5535f8]
2020-10-18 18:29:06.686 DEBUG 14928 --- [nio-8080-exec-4] o.s.web.servlet.DispatcherServlet        : Completed 200 OK
2020-10-18 18:29:06.689 DEBUG 14928 --- [nio-8080-exec-3] o.s.web.servlet.DispatcherServlet        : GET "/swagger-resources", parameters={}
2020-10-18 18:29:06.689 DEBUG 14928 --- [nio-8080-exec-3] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped to springfox.documentation.swagger.web.ApiResourceController#swaggerResources()
2020-10-18 18:29:06.689 DEBUG 14928 --- [nio-8080-exec-3] o.s.w.s.m.m.a.HttpEntityMethodProcessor  : Using 'application/json', given [application/json] and supported [application/json, application/*+json]
2020-10-18 18:29:06.690 DEBUG 14928 --- [nio-8080-exec-3] o.s.w.s.m.m.a.HttpEntityMethodProcessor  : Writing [[springfox.documentation.swagger.web.SwaggerResource@59507de0]]
2020-10-18 18:29:06.690 DEBUG 14928 --- [nio-8080-exec-3] o.s.web.servlet.DispatcherServlet        : Completed 200 OK
2020-10-18 18:29:06.719 DEBUG 14928 --- [nio-8080-exec-5] o.s.web.servlet.DispatcherServlet        : GET "/v2/api-docs", parameters={}
2020-10-18 18:29:06.720 DEBUG 14928 --- [nio-8080-exec-6] o.s.web.servlet.DispatcherServlet        : GET "/", parameters={}
2020-10-18 18:29:06.721  WARN 14928 --- [nio-8080-exec-6] o.s.web.servlet.PageNotFound             : No mapping for GET /
2020-10-18 18:29:06.721 DEBUG 14928 --- [nio-8080-exec-6] o.s.web.servlet.DispatcherServlet        : Completed 404 NOT_FOUND
2020-10-18 18:29:06.721 DEBUG 14928 --- [nio-8080-exec-6] o.s.web.servlet.DispatcherServlet        : "ERROR" dispatch for GET "/error", parameters={}
2020-10-18 18:29:06.721 DEBUG 14928 --- [nio-8080-exec-6] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped to org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController#error(HttpServletRequest)
2020-10-18 18:29:06.722 DEBUG 14928 --- [nio-8080-exec-6] o.s.w.s.m.m.a.HttpEntityMethodProcessor  : Using 'application/json', given [*/*] and supported [application/json, application/*+json]
2020-10-18 18:29:06.722 DEBUG 14928 --- [nio-8080-exec-6] o.s.w.s.m.m.a.HttpEntityMethodProcessor  : Writing [{timestamp=Sun Oct 18 18:29:06 CEST 2020, status=404, error=Not Found, message=, path=/}]
2020-10-18 18:29:06.723 DEBUG 14928 --- [nio-8080-exec-6] o.s.web.servlet.DispatcherServlet        : Exiting from "ERROR" dispatch, status 404
2020-10-18 18:29:06.726 DEBUG 14928 --- [nio-8080-exec-5] o.s.w.s.m.m.a.HttpEntityMethodProcessor  : Using 'application/json', given [application/json, */*] and supported [application/json, application/*+json]
2020-10-18 18:29:06.726 DEBUG 14928 --- [nio-8080-exec-5] o.s.w.s.m.m.a.HttpEntityMethodProcessor  : Writing [springfox.documentation.spring.web.json.Json@786c5618]
2020-10-18 18:29:06.727 DEBUG 14928 --- [nio-8080-exec-5] o.s.web.servlet.DispatcherServlet        : Completed 200 OK
2020-10-18 18:29:06.744 DEBUG 14928 --- [nio-8080-exec-8] o.s.web.servlet.DispatcherServlet        : GET "/csrf", parameters={}
2020-10-18 18:29:06.745  WARN 14928 --- [nio-8080-exec-8] o.s.web.servlet.PageNotFound             : No mapping for GET /csrf
2020-10-18 18:29:06.745 DEBUG 14928 --- [nio-8080-exec-8] o.s.web.servlet.DispatcherServlet        : Completed 404 NOT_FOUND
2020-10-18 18:29:06.745 DEBUG 14928 --- [nio-8080-exec-8] o.s.web.servlet.DispatcherServlet        : "ERROR" dispatch for GET "/error", parameters={}
2020-10-18 18:29:06.746 DEBUG 14928 --- [nio-8080-exec-8] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped to org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController#error(HttpServletRequest)
2020-10-18 18:29:06.746 DEBUG 14928 --- [nio-8080-exec-8] o.s.w.s.m.m.a.HttpEntityMethodProcessor  : Using 'application/json', given [*/*] and supported [application/json, application/*+json]
2020-10-18 18:29:06.746 DEBUG 14928 --- [nio-8080-exec-8] o.s.w.s.m.m.a.HttpEntityMethodProcessor  : Writing [{timestamp=Sun Oct 18 18:29:06 CEST 2020, status=404, error=Not Found, message=, path=/csrf}]
2020-10-18 18:29:06.747 DEBUG 14928 --- [nio-8080-exec-8] o.s.web.servlet.DispatcherServlet        : Exiting from "ERROR" dispatch, status 404

代码中有两个问题。首先,
@Value
不适用于静态字段。因此,所有springfox声明的字段都为空。Spring从不在其中设置值。
如果从字段中删除static,Spring将告诉您它找不到类似
api.common.version
api.common.title
的属性。因为
@PropertySource
不加载yml文件。这是官方宣布的


但是有一个解决方法,您可以按照此源代码使用yml文件和
@PropertySource

您在pom.xml中添加了swagger ui吗?您使用的是哪个版本的springfox?很抱歉没有将此信息添加到原始问题中,但我被限制为3000个字符。springfox springfox-swagger 2.9.2 io.springfox springfox swagger ui 2.9.2,招摇过市最终工作正常,但它没有显示方法apiDocumentation()中的内容,具体来说是ApiInfo对象中的内容。Idk如果问题是Spring Boot没有读取属性,或者您是否尝试使用字符串值而不是属性中的值?如果swagger可以显示字符串值,那么您可以确定问题在于读取属性文件。很抱歉,回复太晚,但是我没有直接在那里添加“@Value”属性,而是直接在那里添加了字符串属性,并且它正在工作。但现在的问题是,为什么“@Value”不起作用。我甚至添加了一个PropertySourcesPlaceholder配置器,但它似乎无法解决问题