springboot-admin使用

springboot admin server服務(wù)

官方文檔
Spring Boot Admin is a application to manage and monitor your Spring Boot Applications. The applications register with our Spring Boot Admin Client (via HTTP) or are discovered using Spring Cloud (e.g. Eureka). The UI is just an AngularJs application on top of the Spring Boot Actuator endpoints.

admin server

  • pom.xml
<dependencies>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
      <groupId>de.codecentric</groupId>
      <artifactId>spring-boot-admin-server</artifactId>
      <version>1.5.2</version>
    </dependency>
    <dependency>
      <groupId>de.codecentric</groupId>
      <artifactId>spring-boot-admin-server-ui</artifactId>
      <version>1.5.2</version>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-actuator</artifactId>
    </dependency>

    <dependency>
      <groupId>de.codecentric</groupId>
      <artifactId>spring-boot-admin-server-ui-login</artifactId>
      <version>1.5.2</version>
    </dependency>
    <dependency>
      <groupId>de.codecentric</groupId>
      <artifactId>spring-boot-admin-starter-client</artifactId>
      <version>1.5.2</version>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-security</artifactId>
    </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>

注意client和server的版本甘萧,最好保持一致。

  • application.yml
server:
  port: 8081

management:
  context-path: "/actuator"
  security:
    enabled: false
security:
  basic:
    enabled: false

spring:
  application:
    name: "@pom.artifactId@"
  boot:
    admin:
      url: http://localhost:${server.port}
#      username: "${security.user.name}"       #These two are needed so that the client
#      password: "${security.user.password}"   #can register at the protected server api
#      client:
#        metadata:
#          user.name: "${security.user.name}"          #These two are needed so that the server
#          user.password:  "${security.user.password}" #can access the proteceted client endpoints
  jackson:
    serialization:
      indent_output: true
endpoints:
  health:
    sensitive: false

#security:
#  user:
#    name: user
#    password: pass

這里說明下:

management:
  context-path: "/actuator"
  security:
    enabled: false

這個開啟下,在控制臺方便查看trace等信息。
這里注釋掉的是權(quán)限信息。

  • bootstrap.java
    啟動類
@Configuration
@EnableAutoConfiguration
@SpringBootApplication
@EnableAdminServer

服務(wù)啟動后翻斟,會看到如下

屏幕快照 2017-08-19 下午4.08.03.png

這個時候看到服務(wù)已經(jīng)啟動了。

admin client

adminclient也是一個springboot工程

  • application.yml文件
spring:
  application:
    name: bootadmin-client
  boot:
    admin:
      url: http://localhost:8081
      client:
        name: ${spring.application.name}
#        enabled: true
#        metadata:
#          user.name: ${security.user.name}
#          user.password: ${security.user.password}
  jackson:
      serialization:
        indent_output: true
server:
  port: 8002

management:
  context-path: "/actuator"
  security:
    enabled: false
security:
  basic:
    enabled: false
#
#security:
#  user:
#    name: user
#    password: pass

這里廢話不多說,直接貼代碼亿乳。大家自己試下就行了。

有個注意的點是:client的版本的問題径筏,如果不一致葛假,可能會導(dǎo)致注冊不上去,如下保證client和server的client的版本一致。

  • pom.xml
<dependencies>
    <dependency>
      <groupId>de.codecentric</groupId>
      <artifactId>spring-boot-admin-starter-client</artifactId>
      <version>1.5.2</version>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-test</artifactId>
    </dependency>

  </dependencies>

服務(wù)啟動后滋恬,可以看到聊训,springboot的client已經(jīng)注冊上去了:

屏幕快照 2017-08-19 下午4.15.20.png

當(dāng)然,這里也可以用eureka或者consul來做服務(wù)的注冊和發(fā)現(xiàn)恢氯。即client和server通過eureka或者consul來進(jìn)行服務(wù)的注冊和發(fā)現(xiàn)带斑。因為兩者都是springboot的web項目。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末勋拟,一起剝皮案震驚了整個濱河市勋磕,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌敢靡,老刑警劉巖挂滓,帶你破解...
    沈念sama閱讀 219,270評論 6 508
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異啸胧,居然都是意外死亡赶站,警方通過查閱死者的電腦和手機,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,489評論 3 395
  • 文/潘曉璐 我一進(jìn)店門吓揪,熙熙樓的掌柜王于貴愁眉苦臉地迎上來亲怠,“玉大人,你說我怎么就攤上這事柠辞⊥呕啵” “怎么了?”我有些...
    開封第一講書人閱讀 165,630評論 0 356
  • 文/不壞的土叔 我叫張陵叭首,是天一觀的道長习勤。 經(jīng)常有香客問我,道長焙格,這世上最難降的妖魔是什么图毕? 我笑而不...
    開封第一講書人閱讀 58,906評論 1 295
  • 正文 為了忘掉前任,我火速辦了婚禮眷唉,結(jié)果婚禮上予颤,老公的妹妹穿的比我還像新娘囤官。我一直安慰自己,他們只是感情好蛤虐,可當(dāng)我...
    茶點故事閱讀 67,928評論 6 392
  • 文/花漫 我一把揭開白布党饮。 她就那樣靜靜地躺著,像睡著了一般驳庭。 火紅的嫁衣襯著肌膚如雪刑顺。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,718評論 1 305
  • 那天饲常,我揣著相機與錄音蹲堂,去河邊找鬼。 笑死贝淤,一個胖子當(dāng)著我的面吹牛柒竞,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播霹娄,決...
    沈念sama閱讀 40,442評論 3 420
  • 文/蒼蘭香墨 我猛地睜開眼能犯,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了犬耻?” 一聲冷哼從身側(cè)響起踩晶,我...
    開封第一講書人閱讀 39,345評論 0 276
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎枕磁,沒想到半個月后渡蜻,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,802評論 1 317
  • 正文 獨居荒郊野嶺守林人離奇死亡计济,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,984評論 3 337
  • 正文 我和宋清朗相戀三年茸苇,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片沦寂。...
    茶點故事閱讀 40,117評論 1 351
  • 序言:一個原本活蹦亂跳的男人離奇死亡学密,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出传藏,到底是詐尸還是另有隱情腻暮,我是刑警寧澤,帶...
    沈念sama閱讀 35,810評論 5 346
  • 正文 年R本政府宣布毯侦,位于F島的核電站哭靖,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏侈离。R本人自食惡果不足惜试幽,卻給世界環(huán)境...
    茶點故事閱讀 41,462評論 3 331
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望卦碾。 院中可真熱鬧铺坞,春花似錦起宽、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,011評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至腿短,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間绘梦,已是汗流浹背橘忱。 一陣腳步聲響...
    開封第一講書人閱讀 33,139評論 1 272
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留卸奉,地道東北人钝诚。 一個月前我還...
    沈念sama閱讀 48,377評論 3 373
  • 正文 我出身青樓,卻偏偏與公主長得像榄棵,于是被迫代替她去往敵國和親凝颇。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 45,060評論 2 355

推薦閱讀更多精彩內(nèi)容