嗨,我用swagger UI有問題。我有這個類似的配置文件。Swagger UI CORS配置Java CXF球衣REST API
<bean id="resourceWriter" class="com.wordnik.swagger.jaxrs.listing.ResourceListingProvider" />
<bean id="apiWriter" class="com.wordnik.swagger.jaxrs.listing.ApiDeclarationProvider" />
<bean id="swaggerResourceJSON" class="com.wordnik.swagger.jaxrs.listing.ApiListingResourceJSON" />
<jaxrs:server id="swaggerAPI" address="/swagger">
<jaxrs:serviceBeans>
<ref bean="swaggerResourceJSON"/>
</jaxrs:serviceBeans>
<jaxrs:providers>
<bean class="org.codehaus.jackson.jaxrs.JacksonJsonProvider"/>
<bean class="com.ge.aviation.svc.fss.exception.WebExceptionHandler"/>
<ref bean="resourceWriter"/>
<ref bean="apiWriter"/>
</jaxrs:providers>
</jaxrs:server>
<bean id="swaggerConfig" class="com.wordnik.swagger.jaxrs.config.BeanConfig">
<property name="resourcePackage" value="package.of.my.service"/>
<property name="version" value="1.0.0"/>
<property name="basePath" value="http://localhost:8090/"/>
<property name="title" value="Sample Service"/>
<property name="description" value="Service for storing, searching, and retrieving files."/>
<property name="contact" value="[email protected]"/>
<property name="scan" value="true"/>
</bean>
然後我的服務器運行完美,並且有一個放屁UI的終點。 http://localhost:8095/api/api-docs/
然後我複製這個網址在瀏覽器中它會顯示Json文件。但我已經複製了我的tomcat中的swagger UI dist文件(上面提到的不是同一個服務器)然後添加上面的URL然後IT說Can't read from server. It may not have the appropriate access-control-origin settings
。我發現錯誤是https://github.com/swagger-api/swagger-ui/issues/146和https://github.com/swagger-api/swagger-ui#cors-support但我想知道如何cors設置ApiListingResourceJSON類,它有API文檔的終點。
因此,您不再使用io.swagger.jaxrs.listing.ApiListingResource並實施您的資源嗎? –