Spring Boot Deployment Strategy

339 views Asked by At

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?

1

There are 1 answers

2
Liping Huang On BEST ANSWER

There are two approaches to do this.

  1. 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 the springfox-swagger2 dependency.

  2. 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 the spring.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 in application.properties to makes spring-boot-actuator run on another TCP port.