SpringFox context path duplicated when deployed to Tomcat - spring-boot

I have a Spring Boot resource server using SpringFox to generate Swagger UI documentation for the REST API. I'm using Spring version 2.2.4.RELEASE and SpringFox version 3.0.0-SNAPSHOT.
When I run the application self hosted the URLs in the documentation are correct, they look like this:
http://localhost:8080/customers
But when I run the same application on tomcat the URLs look like this:
https://myapp.azurewebsites.net/my-app-1.0.0/my-app-1.0.0/customers
The application path is duplicated for all the APIs, the path should be:
https://myapp.azurewebsites.net/my-app-1.0.0/customers
Another issue is the api-docs link, this is wrong for the self hosted but correct for tomcat hosted environments. Both hosting environments including the application which is wrong when self hosted but then its not duplicated like all the others in tomcat:
http://localhost:8080/my-app-1.0.0/v2/api-docs
Also, the documentation is including the application path in the documentation (not duplicated here). The application path is not included when running self hosted.
I tried specifying the context path in the application.yml file but this had no effect (I tried both server.servlet.contextPath and server.servlet.context-path)
How can I get SpringFox to generate the correct URLs?

Related

Does every spring boot application create a tomcat container to be able to run?

For example,
I understand adding specific dependencies like spring-boot-starter-web that contains tomcat as transitive dependency triggers the spring framework to initialize tomcat container but I want to know if we say a spring-boot application is running, does it imply always that tomcat is also running?
I want to know if we say a spring-boot application is running, does it imply always that tomcat is also running?
No, it doesn't.
Spring boot can be used for both web applications and non-web applications.
For web applications you can use tomcat/jetty/undertow/netty for example, its up to you to chose what works for you the best.
If you don't want to run an embedded version of the web server you can opt for creating a WAR file and place it into the web server prepared in-advance.
If you don't want to run web application at all (something that is built around "Request - Response" way of work in the most broad sense) - you can create a "CommandLineRunner" - in this case you don't need to depend on neither web-mvc nor webflux. For more information about Command Line Runners read here for example
You can have an embedded server in your JAR that is able to be run on its own. By default it is Tomcat but you can change this to others, like Jetty. Additional details:
https://docs.spring.io/spring-boot/docs/2.0.6.RELEASE/reference/html/howto-embedded-web-servers.html
If you don't want to have an embedded server and you want to deploy your application you can also create WAR files instead of JAR files. Additional details:
https://www.baeldung.com/spring-boot-no-web-server
https://spring.io/guides/gs/convert-jar-to-war/

Defining context path for spring boot application in external tomcat

I have a spring boot application abc.myapp.war, that is deployed on external tomcat server. By default the tomcat uses the war file name as the context path of the application deployed so it becomes http://localhost:8080/abc.myapp, but I want to have a custom context path like http://localhost:8080/abc/myapp.
I have read through other post they suggest using context tag in server.xml of tomcat, but there is not clear mention how to use it. Can anyone suggest any reference or way to change the context path of the application.
Other ways of doing this are also welcome.
If you want your app to appear with a context path of /abc/myapp you don't have to write any context file, just rename the WAR file to abc#myapp.war: the # will be converted to / (cf. Tomcat documentation for more examples).

Spring Boot: Embedded servlet container is not working properly

My project is using MDHT(Model Driven Health Tools) Runtime Api Library which is based on Eclipse Modeling Framework(EMF). It works when servers in Spring MVC project. But for some reason the EMF package registry is not getting loaded properly and therefore it cannot deserialize as a Consol CCD document when try to servers in Sprint Boot project.
Code Sample:
Mu2consolPackage.eINSTANCE.unload();
ConsolPackage.eINSTANCE.eClass();
CDAUtil.load(in, result);
Link:
MDHT(https://github.com/mdht/mdht-models)
User Documentation (https://www.projects.openhealthtools.org/sf/wiki/do/viewPage/projects.mdht/wiki/User%20Documentation)
Edit:
After changing to use external tomcat to deploy instead of spring boot embedded servlet container. It works, but still cannot resolve using embedded container.

Springboot finds files in src/main/webapp but not src/main/webapp/anything

I'm using Sprint boot to run a web application. I did not configure any classes explicitly. I have a strange problem. When running the web server using gradle bootRun, I am able to access files that are directly under webapp folder but not a sub-folder like webapp/something.
I'm not posting any code here because there is nothing explicitly I configured different from a default spring boot web app. I'm using structure as in https://github.com/jhipster/jhipster-sample-app-gradle
Anyone faced this problem before ?

swagger ui not working for swagger version 2

I am currently working on a project involving spring-boot and swagger. I have upgraded my maven spring boot project to the latest Swagger using the link Upgrade to version2.
I am currently using the Swagger-UI which I have configured from the link Swagger-UI with Spring Boot
I try to access the url : localhost:8080/swagger/index.html after deploying the app successfully on my tomcat server. Unfortunately, it does not work and I am unable to view the swagger-ui in my browser. How do I go on about it further?
I think you're mixing the documentation of 2 versions of the library. The second link points to an older version of the springfox library. Please follow the instructions in the latest snapshot of the documentation. If you've configured everything correctly you should see the swagger-ui at http://localhost:8080[/CONTEXT-PATH]/swagger-ui.html. Depending on how you've set your springboot app the context path is optional.

Resources