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項目。