我有一个使用Apache CXF和Embedded Jetty的REST服务。我想使用CXF Swagger2Feature来实现swagger文档,但是swagger UI返回"没有在规范中定义的操作!"
我试图使用注释和属性,但无论我做什么,都会显示相同的输出。
这是我的代码:
public class AppConfig {
@Bean( destroyMethod = "shutdown" )
public SpringBus cxf() {
return new SpringBus();
}
@Bean
public Server jaxRsServer() {
Swagger2Feature feature = new Swagger2Feature();
feature.setUsePathBasedConfig(true);
feature.setResourcePackage("com.phoenixbv.rs");
feature.setResourcePackage(MaterialsRestService.class.getPackage().getName());
feature.setScanAllResources(true);
JAXRSServerFactoryBean factory = RuntimeDelegate.getInstance().createEndpoint( jaxRsApiApplication(), JAXRSServerFactoryBean.class );
factory.setServiceBeans( Arrays.< Object >asList(baseRestService(), peopleRestService(),materialsRestService(),batchRestService(),billingRestService(),locationRestService() ) );
factory.setAddress(factory.getAddress() );
factory.setProviders( Arrays.< Object >asList( jsonProvider(), authenticationService() ) );
factory.getFeatures().add(feature);
return factory.create();
}
服务类。
@Path( "/materials" )
@Api(value="Materials", description = "Endpoint for Material specific operations")
public class MaterialsRestService extends BaseRestService {
@Inject
private GenericUserRightsUtil genericUserRightsUtil;
@Inject
private PxMaterialService materialsService;
@Produces( { "application/json" } )
@GET
@ApiOperation(value = "GetAllMaterials", notes = "Returns a list of materials", response = MaterialsRestService.class)
@ApiResponse(code = 200, message = "Successful retrieval of all materials", response = MaterialsRestService.class)
public Response getMaterialList(@Context SecurityContext securityContext) {
Principal principal = securityContext.getUserPrincipal();
String empid = principal.getName();
Employee emp = getLoggedInUser(empid);
if((!genericUserRightsUtil.get(emp, Material.class).hasRights(UserRights.Dump))){
return null;
}
return Response.status(200).entity(materialsService.getMaterialList()).build();
}
答案 0 :(得分:0)
更改swagger-ui和service-description-swagger的依赖项中的工件版本为我解决了问题
&#xA;&#xA;目前我正在使用:
&#XA;&#XA;<代码>&LT;依赖性&GT;&#XA;&LT;的groupId&GT; org.apache.cxf&LT; /的groupId&GT;&#XA;&LT; artifactId的&GT; CXF-RT -rs-service-description-swagger&lt; / artifactId&gt;&#xA;&lt; version&gt; 3.1.13&lt; / version&gt;&#xA;&lt; / dependency&gt;&#xA;&#xA;&lt;! - https ://mvnrepository.com/artifact/org.webjars/swagger-ui - &gt;&#xA;&lt; dependency&gt;&#xA;&lt; groupId&gt; org.webjars&lt; / groupId&gt;&#xA;&lt; artifactId&gt ;招摇-UI&LT; / artifactId的&GT;&#XA;&LT;版本&GT; 3.1.5&LT; /版本&GT;&#XA;&LT; /依赖性&GT;&#XA; 代码>&#XA;