Am implementing the swagger 2 using Spring Boot. Using Dependencies-
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.4.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.4.0</version>
</dependency>
It works good. But want to implement swagger in such a way that in production swagger does not get deployed. Also will it be possible to host the swagger build differently than the application build on different host machines?
There are two approaches to do this.
Maven profile
By intrudue a maven profile like 'swagger' and add the
springfox-swagger-ui
related depdencenty to this maven profile. As maybe you need to use some swagger annotations in the java code, so it cannot eliminate thespringfox-swagger2
dependency.Spring profile( should be more better than option 1 )
For a standard spring-boot swagger2 config class, for example you can add the
@Profile("swagger")
annoation to enable the swagger2 integration only when add thespring.profiles.active=swagger
in app running.For the different host machines, I has no idea about that, but as my understanding, swagger will select all the spring boot endpoints so suppose you cannot leave them alone. But there is a library which can provides a way to publish springfox-swagger2 on spring boot actuator. so you can add
management.port=8181
property inapplication.properties
to makes spring-boot-actuator run on another TCP port.