这是什么问题?项目结构:swaggenConfig位于automate.api.Config.swagg.swaggenconfiguration
automate.api.web.Auth.keycloak.falconkeycloakconfigurerAdapter中
依赖关系
至于Spring靴
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.3.RELEASE</version>
<relativePath/>
</parent>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>${spring.springfox-swagger2.version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>${spring.springfox-swagger2.version}</version>
</dependency>
@Configuration
@EnableSwagger2
public class SwaggerConfiguration {
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build();
}
}
@Override
protected void configureAccessRules(final HttpSecurity http) throws Exception {
http.csrf()
.disable()
.authorizeRequests()
.antMatchers("/actuator/health")
.permitAll()
.antMatchers(HttpMethod.GET,
"/v2/api-docs",
"/swagger-resources/**",
"/swagger-ui.html**",
"/webjars/**",
"favicon.ico")
.permitAll();
}
我的一个控制器的示例我的所有控制器都像/api/...
一样映射
@RestController
@RequestMapping(value = "/api", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public class ExampleResource {
private ExampleFacade catalog;
@Autowired
public ExampleResource(ExampleFacade catalog) {
this.catalog = catalog;
}
@RequestMapping(method = RequestMethod.GET, value = "/examples")
public List<ExampleDTO> index() {
return catalog.listExamples();
}
}
发行
/v2/api-docs
工作得很好,我得到了所有endpoint及其详细信息/swagger-ui.html
弹出一个显示“无法推断基本URL......”
logging:
level:
org:
springframework:
web: TRACE
[2019-05-22 21:12:06] TRACE [nio-8080-exec-1] o.s.w.s.DispatcherServlet GET "/v2/api-docs", parameters={}, headers={masked} in DispatcherServlet 'dispatcherServlet'
[2019-05-22 21:12:06] TRACE [nio-8080-exec-1] o.s.w.s.m.m.a.ServletInvocableHandlerMethod Arguments: [null, SecurityContextHolderAwareRequestWrapper[ org.springframework.security.web.header.HeaderWriterFilter$HeaderWriterRequest@b9ed904]]
[2019-05-22 21:12:06] DEBUG [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/webp, image/apng, application/signed-exchange;v=b3, application/xml;q=0.9, */*;q=0.8] and supported [application/json, application/*+json, application/json, application/*+json]
[2019-05-22 21:12:06] TRACE [nio-8080-exec-1] o.s.w.s.m.m.a.HttpEntityMethodProcessor Writing [BaseView(data=springfox.documentation.spring.web.json.Json@65455d18)]
[2019-05-22 21:12:06] TRACE [nio-8080-exec-1] o.s.w.s.DispatcherServlet No view rendering, null ModelAndView returned.
[2019-05-22 21:12:06] DEBUG [nio-8080-exec-1] o.s.w.s.DispatcherServlet Completed 200 OK, headers={masked}
[2019-05-22 21:12:10] TRACE [nio-8080-exec-2] o.s.w.s.DispatcherServlet GET "/swagger-ui.html", parameters={}, headers={masked} in DispatcherServlet 'dispatcherServlet'
[2019-05-22 21:12:10] TRACE [nio-8080-exec-2] o.s.w.s.h.SimpleUrlHandlerMapping Mapped to HandlerExecutionChain with [ResourceHttpRequestHandler ["classpath:/META-INF/resources/", "classpath:/resources/", "classpath:/static/", "classpath:/public/", "/"]] and 5 interceptors
[2019-05-22 21:12:10] TRACE [nio-8080-exec-2] o.s.w.s.DispatcherServlet No view rendering, null ModelAndView returned.
[2019-05-22 21:12:10] DEBUG [nio-8080-exec-2] o.s.w.s.DispatcherServlet Completed 200 OK, headers={masked}
[2019-05-22 21:12:10] TRACE [nio-8080-exec-3] o.s.w.s.DispatcherServlet GET "/webjars/springfox-swagger-ui/springfox.css?v=2.9.2", parameters={masked}, headers={masked} in DispatcherServlet 'dispatcherServlet'
[2019-05-22 21:12:10] TRACE [nio-8080-exec-4] o.s.w.s.DispatcherServlet GET "/webjars/springfox-swagger-ui/swagger-ui.css?v=2.9.2", parameters={masked}, headers={masked} in DispatcherServlet 'dispatcherServlet'
[2019-05-22 21:12:10] TRACE [nio-8080-exec-3] o.s.w.s.h.SimpleUrlHandlerMapping Matching patterns [/webjars/**, /**]
[2019-05-22 21:12:10] TRACE [nio-8080-exec-3] o.s.w.s.h.SimpleUrlHandlerMapping Mapped to HandlerExecutionChain with [ResourceHttpRequestHandler ["classpath:/META-INF/resources/webjars/"]] and 5 interceptors
[2019-05-22 21:12:10] TRACE [nio-8080-exec-4] o.s.w.s.h.SimpleUrlHandlerMapping Matching patterns [/webjars/**, /**]
[2019-05-22 21:12:10] TRACE [nio-8080-exec-4] o.s.w.s.h.SimpleUrlHandlerMapping Mapped to HandlerExecutionChain with [ResourceHttpRequestHandler ["classpath:/META-INF/resources/webjars/"]] and 5 interceptors
[2019-05-22 21:12:10] TRACE [nio-8080-exec-6] o.s.w.s.DispatcherServlet GET "/webjars/springfox-swagger-ui/swagger-ui-bundle.js?v=2.9.2", parameters={masked}, headers={masked} in DispatcherServlet 'dispatcherServlet'
[2019-05-22 21:12:10] TRACE [nio-8080-exec-3] o.s.w.s.DispatcherServlet No view rendering, null ModelAndView returned.
[2019-05-22 21:12:10] DEBUG [nio-8080-exec-3] o.s.w.s.DispatcherServlet Completed 200 OK, headers={masked}
[2019-05-22 21:12:10] TRACE [nio-8080-exec-5] o.s.w.s.DispatcherServlet GET "/webjars/springfox-swagger-ui/swagger-ui-standalone-preset.js?v=2.9.2", parameters={masked}, headers={masked} in DispatcherServlet 'dispatcherServlet'
[2019-05-22 21:12:10] TRACE [nio-8080-exec-7] o.s.w.s.DispatcherServlet GET "/webjars/springfox-swagger-ui/springfox.js?v=2.9.2", parameters={masked}, headers={masked} in DispatcherServlet 'dispatcherServlet'
[2019-05-22 21:12:10] TRACE [nio-8080-exec-6] o.s.w.s.h.SimpleUrlHandlerMapping Matching patterns [/webjars/**, /**]
[2019-05-22 21:12:10] TRACE [nio-8080-exec-6] o.s.w.s.h.SimpleUrlHandlerMapping Mapped to HandlerExecutionChain with [ResourceHttpRequestHandler ["classpath:/META-INF/resources/webjars/"]] and 5 interceptors
[2019-05-22 21:12:10] TRACE [nio-8080-exec-5] o.s.w.s.h.SimpleUrlHandlerMapping Matching patterns [/webjars/**, /**]
[2019-05-22 21:12:10] TRACE [nio-8080-exec-5] o.s.w.s.h.SimpleUrlHandlerMapping Mapped to HandlerExecutionChain with [ResourceHttpRequestHandler ["classpath:/META-INF/resources/webjars/"]] and 5 interceptors
[2019-05-22 21:12:10] TRACE [nio-8080-exec-7] o.s.w.s.h.SimpleUrlHandlerMapping Matching patterns [/webjars/**, /**]
[2019-05-22 21:12:10] TRACE [nio-8080-exec-7] o.s.w.s.h.SimpleUrlHandlerMapping Mapped to HandlerExecutionChain with [ResourceHttpRequestHandler ["classpath:/META-INF/resources/webjars/"]] and 5 interceptors
[2019-05-22 21:12:10] TRACE [nio-8080-exec-4] o.s.w.s.DispatcherServlet No view rendering, null ModelAndView returned.
[2019-05-22 21:12:10] DEBUG [nio-8080-exec-4] o.s.w.s.DispatcherServlet Completed 200 OK, headers={masked}
[2019-05-22 21:12:10] TRACE [nio-8080-exec-7] o.s.w.s.DispatcherServlet No view rendering, null ModelAndView returned.
[2019-05-22 21:12:10] DEBUG [nio-8080-exec-7] o.s.w.s.DispatcherServlet Completed 200 OK, headers={masked}
[2019-05-22 21:12:10] TRACE [nio-8080-exec-5] o.s.w.s.DispatcherServlet No view rendering, null ModelAndView returned.
[2019-05-22 21:12:10] DEBUG [nio-8080-exec-5] o.s.w.s.DispatcherServlet Completed 200 OK, headers={masked}
[2019-05-22 21:12:10] TRACE [nio-8080-exec-6] o.s.w.s.DispatcherServlet No view rendering, null ModelAndView returned.
[2019-05-22 21:12:10] DEBUG [nio-8080-exec-6] o.s.w.s.DispatcherServlet Completed 200 OK, headers={masked}
[2019-05-22 21:12:10] TRACE [nio-8080-exec-8] o.s.w.s.DispatcherServlet GET "/swagger-resources/configuration/ui", parameters={}, headers={masked} in DispatcherServlet 'dispatcherServlet'
[2019-05-22 21:12:10] TRACE [nio-8080-exec-8] o.s.w.s.m.m.a.RequestMappingHandlerMapping Mapped to public org.springframework.http.ResponseEntity<springfox.documentation.swagger.web.UiConfiguration> springfox.documentation.swagger.web.ApiResourceController.uiConfiguration()
[2019-05-22 21:12:10] TRACE [nio-8080-exec-8] o.s.w.s.m.m.a.ServletInvocableHandlerMethod Arguments: []
[2019-05-22 21:12:10] DEBUG [nio-8080-exec-8] o.s.w.s.m.m.a.HttpEntityMethodProcessor Using 'application/json', given [application/json] and supported [application/json, application/*+json, application/json, application/*+json]
[2019-05-22 21:12:10] TRACE [nio-8080-exec-8] o.s.w.s.m.m.a.HttpEntityMethodProcessor Writing [BaseView(data=springfox.documentation.swagger.web.UiConfiguration@7594a0c7)]
[2019-05-22 21:12:10] TRACE [nio-8080-exec-8] o.s.w.s.DispatcherServlet No view rendering, null ModelAndView returned.
[2019-05-22 21:12:10] DEBUG [nio-8080-exec-8] o.s.w.s.DispatcherServlet Completed 200 OK, headers={masked}
[2019-05-22 21:12:10] TRACE [nio-8080-exec-9] o.s.w.s.DispatcherServlet GET "/swagger-resources/configuration/security", parameters={}, headers={masked} in DispatcherServlet 'dispatcherServlet'
[2019-05-22 21:12:10] TRACE [nio-8080-exec-9] o.s.w.s.m.m.a.RequestMappingHandlerMapping Mapped to public org.springframework.http.ResponseEntity<springfox.documentation.swagger.web.SecurityConfiguration> springfox.documentation.swagger.web.ApiResourceController.securityConfiguration()
[2019-05-22 21:12:10] TRACE [nio-8080-exec-9] o.s.w.s.m.m.a.ServletInvocableHandlerMethod Arguments: []
[2019-05-22 21:12:10] DEBUG [nio-8080-exec-9] o.s.w.s.m.m.a.HttpEntityMethodProcessor Using 'application/json', given [application/json] and supported [application/json, application/*+json, application/json, application/*+json]
[2019-05-22 21:12:10] TRACE [nio-8080-exec-9] o.s.w.s.m.m.a.HttpEntityMethodProcessor Writing [BaseView(data=springfox.documentation.swagger.web.SecurityConfiguration@4605258b)]
[2019-05-22 21:12:10] TRACE [nio-8080-exec-9] o.s.w.s.DispatcherServlet No view rendering, null ModelAndView returned.
[2019-05-22 21:12:10] DEBUG [nio-8080-exec-9] o.s.w.s.DispatcherServlet Completed 200 OK, headers={masked}
[2019-05-22 21:12:10] TRACE [io-8080-exec-10] o.s.w.s.DispatcherServlet GET "/swagger-resources", parameters={}, headers={masked} in DispatcherServlet 'dispatcherServlet'
[2019-05-22 21:12:10] TRACE [io-8080-exec-10] o.s.w.s.m.m.a.RequestMappingHandlerMapping Mapped to public org.springframework.http.ResponseEntity<java.util.List<springfox.documentation.swagger.web.SwaggerResource>> springfox.documentation.swagger.web.ApiResourceController.swaggerResources()
[2019-05-22 21:12:10] TRACE [io-8080-exec-10] o.s.w.s.m.m.a.ServletInvocableHandlerMethod Arguments: []
[2019-05-22 21:12:10] DEBUG [io-8080-exec-10] o.s.w.s.m.m.a.HttpEntityMethodProcessor Using 'application/json', given [application/json] and supported [application/json, application/*+json, application/json, application/*+json]
[2019-05-22 21:12:10] TRACE [io-8080-exec-10] o.s.w.s.m.m.a.HttpEntityMethodProcessor Writing [BaseView(data=[springfox.documentation.swagger.web.SwaggerResource@b35c0d2])]
[2019-05-22 21:12:10] TRACE [io-8080-exec-10] o.s.w.s.DispatcherServlet No view rendering, null ModelAndView returned.
[2019-05-22 21:12:10] DEBUG [io-8080-exec-10] o.s.w.s.DispatcherServlet Completed 200 OK, headers={masked}
[2019-05-22 21:12:11] TRACE [nio-8080-exec-1] o.s.w.s.DispatcherServlet GET "/null/swagger-resources/configuration/ui", parameters={}, headers={masked} in DispatcherServlet 'dispatcherServlet'
[2019-05-22 21:12:11] TRACE [nio-8080-exec-1] o.s.w.s.h.SimpleUrlHandlerMapping Mapped to HandlerExecutionChain with [ResourceHttpRequestHandler ["classpath:/META-INF/resources/", "classpath:/resources/", "classpath:/static/", "classpath:/public/", "/"]] and 5 interceptors
[2019-05-22 21:12:11] DEBUG [nio-8080-exec-1] o.s.w.s.r.ResourceHttpRequestHandler Resource not found
[2019-05-22 21:12:11] TRACE [nio-8080-exec-1] o.s.w.s.DispatcherServlet No view rendering, null ModelAndView returned.
[2019-05-22 21:12:11] DEBUG [nio-8080-exec-1] o.s.w.s.DispatcherServlet Completed 404 NOT_FOUND, headers={masked}
[2019-05-22 21:12:11] TRACE [nio-8080-exec-1] o.s.w.s.DispatcherServlet "ERROR" dispatch for GET "/error", parameters={}, headers={masked} in DispatcherServlet 'dispatcherServlet'
[2019-05-22 21:12:11] TRACE [nio-8080-exec-1] o.s.w.s.m.m.a.RequestMappingHandlerMapping Mapped to public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
[2019-05-22 21:12:11] TRACE [nio-8080-exec-1] o.s.w.s.m.m.a.ServletInvocableHandlerMethod Arguments: [SecurityContextHolderAwareRequestWrapper[ FirewalledRequest[ org.apache.catalina.core.ApplicationHttpRequest@dc7df80]]]
[2019-05-22 21:12:11] DEBUG [nio-8080-exec-1] o.s.w.s.m.m.a.HttpEntityMethodProcessor Using 'application/json', given [application/json] and supported [application/json, application/*+json, application/json, application/*+json]
[2019-05-22 21:12:11] TRACE [nio-8080-exec-1] o.s.w.s.m.m.a.HttpEntityMethodProcessor Writing [BaseView(data={timestamp=Wed May 22 21:12:11 CEST 2019, status=404, error=Not Found, message=No message available, path=/null/swagger-resources/configuration/ui})]
[2019-05-22 21:12:11] TRACE [nio-8080-exec-1] o.s.w.s.DispatcherServlet No view rendering, null ModelAndView returned.
[2019-05-22 21:12:11] DEBUG [nio-8080-exec-1] o.s.w.s.DispatcherServlet Exiting from "ERROR" dispatch, status 404, headers={masked}
[2019-05-22 21:12:12] TRACE [nio-8080-exec-2] o.s.w.s.DispatcherServlet GET "/null/swagger-resources/configuration/security", parameters={}, headers={masked} in DispatcherServlet 'dispatcherServlet'
[2019-05-22 21:12:12] TRACE [nio-8080-exec-2] o.s.w.s.h.SimpleUrlHandlerMapping Mapped to HandlerExecutionChain with [ResourceHttpRequestHandler ["classpath:/META-INF/resources/", "classpath:/resources/", "classpath:/static/", "classpath:/public/", "/"]] and 5 interceptors
[2019-05-22 21:12:12] DEBUG [nio-8080-exec-2] o.s.w.s.r.ResourceHttpRequestHandler Resource not found
[2019-05-22 21:12:12] TRACE [nio-8080-exec-2] o.s.w.s.DispatcherServlet No view rendering, null ModelAndView returned.
[2019-05-22 21:12:12] DEBUG [nio-8080-exec-2] o.s.w.s.DispatcherServlet Completed 404 NOT_FOUND, headers={masked}
[2019-05-22 21:12:12] TRACE [nio-8080-exec-2] o.s.w.s.DispatcherServlet "ERROR" dispatch for GET "/error", parameters={}, headers={masked} in DispatcherServlet 'dispatcherServlet'
[2019-05-22 21:12:12] TRACE [nio-8080-exec-2] o.s.w.s.m.m.a.RequestMappingHandlerMapping Mapped to public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
[2019-05-22 21:12:12] TRACE [nio-8080-exec-2] o.s.w.s.m.m.a.ServletInvocableHandlerMethod Arguments: [SecurityContextHolderAwareRequestWrapper[ FirewalledRequest[ org.apache.catalina.core.ApplicationHttpRequest@723fa0fe]]]
[2019-05-22 21:12:12] DEBUG [nio-8080-exec-2] o.s.w.s.m.m.a.HttpEntityMethodProcessor Using 'application/json', given [application/json] and supported [application/json, application/*+json, application/json, application/*+json]
[2019-05-22 21:12:12] TRACE [nio-8080-exec-2] o.s.w.s.m.m.a.HttpEntityMethodProcessor Writing [BaseView(data={timestamp=Wed May 22 21:12:12 CEST 2019, status=404, error=Not Found, message=No message available, path=/null/swagger-resources/configuration/security})]
[2019-05-22 21:12:12] TRACE [nio-8080-exec-2] o.s.w.s.DispatcherServlet No view rendering, null ModelAndView returned.
[2019-05-22 21:12:12] DEBUG [nio-8080-exec-2] o.s.w.s.DispatcherServlet Exiting from "ERROR" dispatch, status 404, headers={masked}
求求你,帮帮我!:)
我仔细研究了这个问题,并阅读了这些问题:
为什么springfox-swagger2 UI告诉我“无法推断基本URL”。
https://github.com/springfox/springfox/issues/2501 https://github.com/springfox/springfox/issues/2396
现在,我设法解决了我的问题。其中一个问题是路径映射。
我需要将配置显式地更改为“/”,如下所示
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@Configuration
@EnableSwagger2
public class SwaggerConfiguration {
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build()
.pathMapping("/");
}
}
另一个问题是我使用了ResponseBodyAdvise
import io.falcon.automate.api.web.views.BaseView;
import io.falcon.automate.api.web.views.ErrorView;
import org.springframework.core.MethodParameter;
import org.springframework.http.MediaType;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.server.ServerHttpRequest;
import org.springframework.http.server.ServerHttpResponse;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice;
@ControllerAdvice
public class ResponseAdvice implements ResponseBodyAdvice<Object> {
@Override
public boolean supports(MethodParameter returnType, Class<? extends HttpMessageConverter<?>> converterType) {
return true;
}
/**
* Wraps all responses in base view class
* @param body
* @param returnType
* @param selectedContentType
* @param selectedConverterType
* @param request
* @param response
* @return
*/
@Override
public Object beforeBodyWrite(
Object body,
MethodParameter returnType,
MediaType selectedContentType,
Class<? extends HttpMessageConverter<?>> selectedConverterType,
ServerHttpRequest request,
ServerHttpResponse response
) {
if (body instanceof ErrorView) {
return body;
}
return new BaseView(body);
}
}
这是一个什么样的问题?项目结构:SwaggerConfig在中的身份验证配置在中 依赖关系 至于Spring靴 我的一个控制器的示例我的所有控制器都映射为 问题 工作很好,我会返回所有endpoint及其详细信息弹出显示“无法推断基本URL......” 我的日志看起来像: 不幸的是,我发现在日志的and处的路径映射有些奇怪:GET“/null/swagger-resources/configur
我使用的以及version。但无法启动swagger-ui(即http://localhost:808/swagger-ui.html)或api-docs(即http://localhost:8080/v2/api-docs)网址。 相同的配置适用于。唯一的区别是在中添加了。 错误详细信息 这是我的 这是昂首阔步的配置 控制器接口 控制器实现 Spring启动应用程序 并使用记录springweb
为什么springfox-swagger2 UI告诉我据我所知,我使用的是典型的Swagger spring-boot配置。 正如您在屏幕截图中看到的,支持UI的swagger-fox url是example.com/api。注意:当我导航到:https://localhost:9600/api/v2/api-docs/时,会得到一个标准的Spring。我怀疑这是问题的根源?我没有看到Spring
为什么springfox-Swagger2UI告诉我
我们在API网关后面有Spring Boot服务。使用SpringFox-2.1.2的早期版本,我们在加载页面时没有任何问题。这适用于Spring Boot1.4.3.Release。从那时起,我们已经升级到引导1.5.7,并将Springfox升级到2.8.0。 现在,如果我们加载页面,我们会得到一个带有以下长消息的警告框。 null 你知道为什么会这样吗?有人面临类似的问题吗?解决办法的建议?
我刚刚将我的Spring Boot应用程序(版本2.3.1.RELEASE)中的Springfox依赖项从2.9.2更新到2.10.4。 由于< code > spring fox . documentation . * 包中的类发生了变化,我不得不将配置类中的注释从 到 还谓词进口从谷歌Guav 当我现在打开 http://localhost:8080/swagger-ui.html 时,我收到