으로 주석 구동 swagger.json에 권한 부여 추가 스프링 부트로 빌드 된 Swagger-annotated Jersey 2.0 웹 서비스에 기본 인증을 Swagger UI에 추가하려고합니다. 내가 사용하고 있습니다 :저지 2 및 스프링 부트
- 봄 부팅 1.5.4
- 스프링 부팅 스타터 저지
- 자신감 UI 3.0.4
- (메이븐 패키지) 자신감 - jersey2-jaxrs 1.5.13 을
내 자원에서 다음 JerseyConfig와 Swagger 주석을 사용하여 swagger.json 파일을 생성 할 수 있습니다. This article was immensely helpful in getting this far.
@Component
public class JerseyConfiguration extends ResourceConfig {
private static Log logger = LogFactory.getLog(JerseyConfiguration.class);
@Value("${spring.jersey.application-path:/}")
private String apiPath;
public JerseyConfiguration() {
registerEndpoints();
configureSwagger();
}
private void registerEndpoints() {
register(MyEndpoints.class);
// Generate Jersey WADL at /<Jersey's servlet path>/application.wadl
register(WadlResource.class);
// Lets us get to static content like swagger
property(ServletProperties.FILTER_STATIC_CONTENT_REGEX, "((/swagger/.*)|(.*\\.html))");
}
/**
* Configure the Swagger documentation for this API.
*/
private void configureSwagger() {
// Creates file at localhost:port/swagger.json
this.register(ApiListingResource.class);
this.register(SwaggerSerializers.class);
BeanConfig config = new BeanConfig();
config.setConfigId("example-jersey-app");
config.setTitle("Spring Boot + Jersey + Swagger");
config.setVersion("2");
config.setContact("Me <[email protected]>");
config.setSchemes(new String[] {"http", "https"});
config.setResourcePackage("com.example.api");
config.setBasePath(this.apiPath);
config.setPrettyPrint(true);
config.setScan(true);
}
}
이제 기본 인증을 사용하여 Swagger UI에서 이러한 서비스에 연결할 수 있기를 원합니다. 스프링으로 구성 했으므로 사이트 인증을 위해 사용할 수 있지만 Swagger UI에서는 사용할 수 없습니다. 유감스럽게도 스프링 부트 examples currently on the Swagger sample site에는 저지 및 인증이 포함되어 있지 않으며 Jersey 예제에는 Spring Boot를 사용하지 않으며 @SpringBootApplication
은 내 프로젝트에서 on을 사용하고 있습니다.
Swagger UI에 Basic Auth를 표시하려면 어떻게합니까?
하늘에 감사하십시오. –
나는 이것을 위해 모든 곳을 찾고있었습니다. –