Tôi đã cố gắng thiết lập swagger-ui với ứng dụng REST mùa xuân của mình. Tôi đang sử dụng spring 4.2.6.RELEASE và swagger core & ui 2.5.0. Tôi không sử dụng chú thích vênh vang, mong muốn vênh vang để nhận chú thích REST mùa xuân.Spring Application: Tại sao swagger-ui không thể thực hiện HTTP GET trên swagger-resources/configuration/ui?
Tôi có thể nhận được vênh vang để tạo tài liệu api và tôi có thể xem nó dưới dạng v2/api-docs.
Tôi có thể nhấn trang swagger-ui.html nhưng nó không hiển thị bất kỳ thông tin api-doc hoặc thông tin điều khiển nào trên trang. Khi bật chế độ trình gỡ lỗi trên trình duyệt, tôi thấy rằng đó là lỗi khi cố gắng TẢI "chuyển đổi tài nguyên/cấu hình/ui" - trả về 404 (Không tìm thấy).
Tôi đã theo các liên kết dưới đây để thiết lập vênh vang-ui http://www.baeldung.com/swagger-2-documentation-for-spring-rest-api
tôi đã bước đầu thiết lập xử lý tài nguyên theo quy định tại các liên kết ở trên nhưng điều đó không giúp được gì và đã cho tôi cùng một lỗi 404. Tôi đã thử tinh chỉnh trình xử lý tài nguyên để xem nó có thể giúp swagger-ui thực hiện GET trên swagger-resources/configuration/ui hay không.
Tại sao swagger-ui không thể TẮT nguồn tài nguyên/cấu hình/ui tài nguyên?
Tôi đã thiết lập trình xử lý tài nguyên của mình như bên dưới.
SwaggerConfiguration
@Configuration
@EnableSwagger2
public class SwaggerConfiguration {
@Bean
public Docket api(){
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build();
//.apiInfo(apiInfo());
}
}
tập tin Web cấu hình
@EnableWebMvc
@Configuration
@Import(SwaggerConfiguration.class)
@ComponentScan("com.bank.direct.services")
public class WebConfig extends WebMvcConfigurerAdapter {
@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> pConverters) {
pConverters.add(RestUtils.getJSONMessageConverter());
}
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("**/**").addResourceLocations("classpath:/META-INF/resources/");
registry
.addResourceHandler("swagger-ui.html")
.addResourceLocations("classpath:/META-INF/resources/swagger-ui.html");
registry
.addResourceHandler("/webjars/**")
.addResourceLocations("classpath:/META-INF/resources/webjars/");
}
}
tôi có một thiết lập SecurityConfig cho webapp, nhưng tôi đã giữ nó đến mức tối thiểu chỉ trong trường hợp nó có thể gây ra bất kỳ sự cố nào.
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
@Configuration
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private AuthenticationService _authenticationService;
@Autowired
public void globalUserDetails(AuthenticationManagerBuilder pAuth) throws Exception {
pAuth.userDetailsService(_authenticationService);
}
@Override
protected void configure(HttpSecurity pHttp) throws Exception {
// Enable HTTP caching
pHttp.headers().cacheControl().disable();
// Configure security
pHttp.httpBasic()
// -- Allow unauthenticated request (must be done before allowing only authenticated requests)
.and()
.authorizeRequests()
.antMatchers("/rest/application/information/").permitAll();
}
Tôi thấy một số bản đồ tài nguyên khi ứng dụng khởi động
2016-08-31 11:24:55 INFO [localhost-startStop-1] RequestMappingHandlerMapping - Mapped "{[/v2/api-docs], phương thức = [GET], tạo ra = [application/json || application/hal + json]} "lên public org.springframework.http.ResponseEntity springfox.documentation.swagger2.web. Swagger2Controller.getDocumentation (java.lang.String, javax.servlet.http.HttpServletRequest) 2016-08-31 11:24:55 THÔNG TIN [localhost-startStop-1] RequestMappingHandlerMapping - Ánh xạ "{[/ swagger-resources/configuration/security]}" lên org.springframework.http.ResponseEntity springfox.documentation .swagger.web.ApiResourceController.securityConfiguration() 2016-08-31 11:24:55 THÔNG TIN [localhost-startStop-1] RequestMappingHandlerMapping - Ánh xạ "{[/ swagger-resources]}" lên org.springframework.http .ResponseEntity> springfox.documentation.swagger.web.ApiResourceController.swaggerResources() 2016/08/31 11:24:55 INFO [localhost-startStop-1] RequestMappingHandlerMapping - Mapped "{[/ vênh vang-nguồn/cấu hình/ui]}" vào org.springframework.http .ResponseEntity springfox.documentation.swagger.web.ApiResourceController.uiConfiguration()
Bạn có giải quyết được vấn đề? Vui lòng cung cấp phản hồi. –