Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use swagger-ui with service deployed in tomcat running on eclipse

I have a REST api running at http://localhost:8080/MyService and can see the JSON produced by swagger at http://localhost:8080/MyService/api-docs. In the Servers project in eclipse I have modified web.xml to include the Cors filter:

<filter>
    <filter-name>CorsFilter</filter-name>
    <filter-class>org.apache.catalina.filters.CorsFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>CorsFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

but when I point swagger-ui (loaded in browser from file system) at http://localhost:8080/MyService/api-docs, I get the following error:

Can't read from server. It may not have the appropriate access-control-origin settings.

like image 508
Rich Ashworth Avatar asked Oct 01 '22 22:10

Rich Ashworth


1 Answers

Adding the Swagger dist directly to the webapps folder did the trick

like image 177
Rich Ashworth Avatar answered Oct 12 '22 10:10

Rich Ashworth