SpringBoot production environment quickly disable Swagger2

method one

Use annotations @Profile({"dev","test"}) indicate in development or test environment open, and in the production shut down.
@ProfileThe value used is based on spring.profiles.activethe specified environmental parameters, refer to previous blog SpringBoot Beginners many environmental profile .

Under brief @Profilecomment

@Profile Annotation role in different scenarios, different classes are given instance. Examples of such DataSource given DataSource instance in a production environment and are given the test environment are different.

@Profile When used, generally in the @Configuration case of using, in a class or method marked, when marked fill a string (e.g. "dev"), as a scene, or a distinction.

In fact, rarely activate the Spring container Profile Through the above manner, usually let the Spring container automatically to read values ​​Profile, and then automatically set. These implementations are typically achieve specific framework or virtual machine parameters / variables related to the environment.

Method Two

Use annotations @ConditionalOnProperty(name = "swagger.enable", havingValue = "true") and then add in the corresponding application.properties/application.yml configuration file  swagger.enable = trueto open, fill in the production environment is not turned off by default Swagger.


The above two methods can be successfully disabled swagger2 according to the current environment, the effect is as follows:

Reference blog:
https://cloud.tencent.com/developer/article/1362768
https://www.jb51.net/article/153492.htm

                        <li class="tool-item tool-active is-like "><a href="javascript:;"><svg class="icon" aria-hidden="true">
                            <use xlink:href="#csdnc-thumbsup"></use>
                        </svg><span class="name">点赞</span>
                        <span class="count"></span>
                        </a></li>
                        <li class="tool-item tool-active is-collection "><a href="javascript:;" data-report-click="{&quot;mod&quot;:&quot;popu_824&quot;}"><svg class="icon" aria-hidden="true">
                            <use xlink:href="#icon-csdnc-Collection-G"></use>
                        </svg><span class="name">收藏</span></a></li>
                        <li class="tool-item tool-active is-share"><a href="javascript:;"><svg class="icon" aria-hidden="true">
                            <use xlink:href="#icon-csdnc-fenxiang"></use>
                        </svg>分享</a></li>
                        <!--打赏开始-->
                                                <!--打赏结束-->
                                                <li class="tool-item tool-more">
                            <a>
                            <svg t="1575545411852" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5717" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200"><defs><style type="text/css"></style></defs><path d="M179.176 499.222m-113.245 0a113.245 113.245 0 1 0 226.49 0 113.245 113.245 0 1 0-226.49 0Z" p-id="5718"></path><path d="M509.684 499.222m-113.245 0a113.245 113.245 0 1 0 226.49 0 113.245 113.245 0 1 0-226.49 0Z" p-id="5719"></path><path d="M846.175 499.222m-113.245 0a113.245 113.245 0 1 0 226.49 0 113.245 113.245 0 1 0-226.49 0Z" p-id="5720"></path></svg>
                            </a>
                            <ul class="more-box">
                                <li class="item"><a class="article-report">文章举报</a></li>
                            </ul>
                        </li>
                                            </ul>
                </div>
                            </div>
            <div class="person-messagebox">
                <div class="left-message"><a href="https://blog.csdn.net/baidu_38083619">
                    <img src="https://profile.csdnimg.cn/1/8/7/3_baidu_38083619" class="avatar_pic" username="baidu_38083619">
                                            <img src="https://g.csdnimg.cn/static/user-reg-year/1x/3.png" class="user-years">
                                    </a></div>
                <div class="middle-message">
                                        <div class="title"><span class="tit"><a href="https://blog.csdn.net/baidu_38083619" data-report-click="{&quot;mod&quot;:&quot;popu_379&quot;}" target="_blank">岁月安然</a></span>
                                            </div>
                    <div class="text"><span>发布了28 篇原创文章</span> · <span>获赞 18</span> · <span>访问量 3万+</span></div>
                </div>
                                <div class="right-message">
                                            <a href="https://im.csdn.net/im/main.html?userName=baidu_38083619" target="_blank" class="btn btn-sm btn-red-hollow bt-button personal-letter">私信
                        </a>
                                                            <a class="btn btn-sm  bt-button personal-watch" data-report-click="{&quot;mod&quot;:&quot;popu_379&quot;}">关注</a>
                                    </div>
                            </div>
                    </div>
    </article>
    
Released five original articles · won praise 0 · Views 255

method one

Guess you like

Origin blog.csdn.net/weixin_32822759/article/details/104396646