国产片侵犯亲女视频播放_亚洲精品二区_在线免费国产视频_欧美精品一区二区三区在线_少妇久久久_在线观看av不卡

服務器之家:專注于服務器技術(shù)及軟件下載分享
分類導航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術(shù)|正則表達式|C/C++|IOS|C#|Swift|Android|VB|R語言|JavaScript|易語言|vb.net|

服務器之家 - 編程語言 - Java教程 - 淺談關(guān)于spring profile的誤解

淺談關(guān)于spring profile的誤解

2021-05-25 13:16Mr_Qi Java教程

這篇文章主要介紹了淺談關(guān)于spring profile的誤解,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧

背景

springprofile大家都是用的溜的飛起~

那么profile的組合如何使用呢???

比如我們這樣使用

?
1
@profile({"prod", "unit-test"})

分析

上述的profile大家應該不會存有疑問 當profile為prod或者unit-test的時候才會生效。

但是如果我們使用非呢~如何確保在某些情況下不生效!

spring提供了常見的!來進行描述

因此如果想要在非生產(chǎn)環(huán)境生效只要簡單的寫成

?
1
@profile({"!prod"})

那么如何在多個環(huán)境下不生效呢???

自作聰明的某些人【我】如下代碼

?
1
@profile({"!prod", "!unit-test"})

那么實際情況是否如此呢???

我們看一下對應的代碼

代碼

profile是通過profilecondition來完成控制的

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
class profilecondition implements condition {
 
  @override
  public boolean matches(conditioncontext context, annotatedtypemetadata metadata) {
   if (context.getenvironment() != null) {
     multivaluemap<string, object> attrs = metadata.getallannotationattributes(profile.class.getname());
     if (attrs != null) {
      for (object value : attrs.get("value")) {
        if (context.getenvironment().acceptsprofiles(((string[]) value))) {
         return true;
        }
      }
      return false;
     }
   }
   return true;
  }
 
}

很明顯可以看到了acceptsprofiles

?
1
2
3
4
5
6
7
8
9
10
11
12
13
/**
 * return whether one or more of the given profiles is active or, in the case of no
 * explicit active profiles, whether one or more of the given profiles is included in
 * the set of default profiles. if a profile begins with '!' the logic is inverted,
 * i.e. the method will return true if the given profile is <em>not</em> active.
 * for example, <pre class="code">env.acceptsprofiles("p1", "!p2")</pre> will
 * return {@code true} if profile 'p1' is active or 'p2' is not active.
 * @throws illegalargumentexception if called with zero arguments
 * or if any profile is {@code null}, empty or whitespace-only
 * @see #getactiveprofiles
 * @see #getdefaultprofiles
 */
boolean acceptsprofiles(string... profiles);

從上述可以看到應該是or的條件

當然代碼如下

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
@override
public boolean acceptsprofiles(string... profiles) {
  assert.notempty(profiles, "must specify at least one profile");
  for (string profile : profiles) {
   if (stringutils.haslength(profile) && profile.charat(0) == '!') {
     if (!isprofileactive(profile.substring(1))) {
      return true;
     }
   }
   else if (isprofileactive(profile)) {
     return true;
   }
  }
  return false;
}

因此可以看到當是!條件的時候會判斷如果當前未激活profile返回true 否則當前是正常條件的換當前profile如果激活則返回true 當上述條件都不滿足才返回false

因此上述邏輯告訴我們其實應該是或者的邏輯。因此

?
1
@profile({"!prod", "!unit-test"})

!prod||!unit-test===>!(prod&&unit-test)  也就是說當prod和unit-test都生效的時候才不會注冊 其他調(diào)均都會注冊生效

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持服務器之家。

原文鏈接:https://my.oschina.net/qixiaobo025/blog/1927580

延伸 · 閱讀

精彩推薦
Weibo Article 1 Weibo Article 2 Weibo Article 3 Weibo Article 4 Weibo Article 5 Weibo Article 6 Weibo Article 7 Weibo Article 8 Weibo Article 9 Weibo Article 10 Weibo Article 11 Weibo Article 12 Weibo Article 13 Weibo Article 14 Weibo Article 15 Weibo Article 16 Weibo Article 17 Weibo Article 18 Weibo Article 19 Weibo Article 20 Weibo Article 21 Weibo Article 22 Weibo Article 23 Weibo Article 24 Weibo Article 25 Weibo Article 26 Weibo Article 27 Weibo Article 28 Weibo Article 29 Weibo Article 30 Weibo Article 31 Weibo Article 32 Weibo Article 33 Weibo Article 34 Weibo Article 35 Weibo Article 36 Weibo Article 37 Weibo Article 38 Weibo Article 39 Weibo Article 40
主站蜘蛛池模板: 日韩中文一区二区三区 | 毛片91 | 日本不卡一区二区三区在线观看 | 国产综合精品一区二区三区 | 99国产精品99久久久久久 | 99视频在线 | 日韩精品电影 | 中文字幕欧美激情 | 亚洲精品一二三 | 日韩精品一区二区三区中文字幕 | 亚洲一区在线免费观看 | 欧美一区三区 | 亚洲午夜成激人情在线影院 | 国产精品福利在线观看 | 91嫩草香蕉 | 岛国搬运工av在线播放 | 亚洲福利二区 | 成人a视频片观看免费 | 亚洲伦理影院 | www.av在线播放 | 国产片在线观看免费观看 | 香蕉尹人网 | 久久se精品一区精品二区 | 国产精品中文字幕在线 | 日韩欧美在线观看一区二区 | 国产日韩视频 | 久久久亚洲国产美女国产盗摄 | 日韩在线一区二区三区 | 色婷婷综合久久久中字幕精品久久 | 欧美激情高清 | 欧美久久久久久久久久久 | 国产精品免费精品自在线观看 | 国产精品久久久久久久久 | av中文字幕在线观看 | 午夜在线小视频 | 欧美影| 亚洲视频自拍 | 欧美激情视频一区二区三区 | 一级a性色生活片久久毛片 国产精品久久久久久久久久免费看 | 青青久久| 明里在线观看 |