In case you ever need to host static content from CXF, try this before jumping off a bridge

For some odd reason, you may find that you really, really want to host some static content on your CXF server. Maybe you want to do something like host Swagger or IO Docs side by side with your REST API and you don’t feel like setting up a whole new service.

And if you’re like me, you’ve already shot yourself in the foot because you bound your RESTful service to the root of your Tomcat webapp. For example, your CXF servlet is bound to http://localhost:8080/petsore/* but you now want http://localhost:8080/petstore/docs/ to host your documentation, and CXF thinks your docs are an API endpoint.

You made your life complicated and set it up like this too, didn’t you?

And maybe you’ve tried to read the impenetrable documentation on the Apache CXF site with its maddening language about servlet initialization params relating to “redirects.” I debugged deep into the CXF sourcecode to figure what’s really going on. You need to start with CXF’s

Now that I’ve said all that, let me get to the bottom line. All you really need to do is make sure you’ve added two initialization params to your web.xml:

In my configuration, I had the Swagger docs under the src/main/webapps folder in my Maven project, so your mileage may vary depending on your configuration.

Good luck out there.