@@ -48,6 +48,7 @@ spring boot demo 是一个用来学习 spring boot 的项目,已经集成 actu | |||||
<module>../spring-boot-demo-helloworld</module> | <module>../spring-boot-demo-helloworld</module> | ||||
<module>../spring-boot-demo-properties</module> | <module>../spring-boot-demo-properties</module> | ||||
<module>../spring-boot-demo-actuator</module> | <module>../spring-boot-demo-actuator</module> | ||||
<module>../spring-boot-demo-admin</module> | |||||
<module>../spring-boot-demo-logback</module> | <module>../spring-boot-demo-logback</module> | ||||
<module>../spring-boot-demo-orm-jpa</module> | <module>../spring-boot-demo-orm-jpa</module> | ||||
<module>../spring-boot-demo-orm-mybatis</module> | <module>../spring-boot-demo-orm-mybatis</module> | ||||
@@ -143,6 +144,7 @@ spring boot demo 是一个用来学习 spring boot 的项目,已经集成 actu | |||||
| [spring-boot-demo-helloworld](./spring-boot-demo-helloworld) | spring-boot 的一个 helloworld | | | [spring-boot-demo-helloworld](./spring-boot-demo-helloworld) | spring-boot 的一个 helloworld | | ||||
| [spring-boot-demo-properties](./spring-boot-demo-properties) | spring-boot 读取配置文件中的内容 | | | [spring-boot-demo-properties](./spring-boot-demo-properties) | spring-boot 读取配置文件中的内容 | | ||||
| [spring-boot-demo-actuator](./spring-boot-demo-actuator) | spring-boot 集成 spring-boot-starter-actuator 用于监控 spring-boot 的启动和运行状态 | | | [spring-boot-demo-actuator](./spring-boot-demo-actuator) | spring-boot 集成 spring-boot-starter-actuator 用于监控 spring-boot 的启动和运行状态 | | ||||
| [spring-boot-demo-admin](./spring-boot-demo-admin) | spring-boot 集成 spring-boot-admin 来可视化的监控 spring-boot 程序的运行状态,可以与 actuator 互相搭配使用 | | |||||
| [spring-boot-demo-logback](./spring-boot-demo-logback) | spring-boot 集成 logback 日志 | | | [spring-boot-demo-logback](./spring-boot-demo-logback) | spring-boot 集成 logback 日志 | | ||||
| [spring-boot-demo-orm-jpa](./spring-boot-demo-orm-jpa) | spring-boot 集成 spring-boot-starter-data-jpa 操作数据库 | | | [spring-boot-demo-orm-jpa](./spring-boot-demo-orm-jpa) | spring-boot 集成 spring-boot-starter-data-jpa 操作数据库 | | ||||
| [spring-boot-demo-orm-mybatis](./spring-boot-demo-orm-mybatis) | spring-boot 集成 [mybatis-spring-boot-starter](https://github.com/mybatis/spring-boot-starter)、[mybatis-spring-boot-starter](https://github.com/alibaba/druid/tree/master/druid-spring-boot-starter) | | | [spring-boot-demo-orm-mybatis](./spring-boot-demo-orm-mybatis) | spring-boot 集成 [mybatis-spring-boot-starter](https://github.com/mybatis/spring-boot-starter)、[mybatis-spring-boot-starter](https://github.com/alibaba/druid/tree/master/druid-spring-boot-starter) | | ||||
@@ -75,7 +75,7 @@ management: | |||||
#### 方法一:(本 demo 中使用的是这种) | #### 方法一:(本 demo 中使用的是这种) | ||||
```yml | |||||
```yaml | |||||
management: | management: | ||||
security: | security: | ||||
enabled: false | enabled: false | ||||
@@ -94,7 +94,7 @@ pom.xml 中添加以下 `spring-boot-starter-security` 依赖: | |||||
并在 `application.yml` 文件中设置访问的密码 | 并在 `application.yml` 文件中设置访问的密码 | ||||
```yml | |||||
```yaml | |||||
security: | security: | ||||
basic: | basic: | ||||
enabled: true | enabled: true | ||||
@@ -0,0 +1,103 @@ | |||||
# spring-boot-demo-admin | |||||
依赖[spring-boot-demo-parent](../spring-boot-demo-parent)、服务端依赖 `spring-boot-demo-admin` 和 `spring-boot-admin-server-ui`、客户端依赖 `spring-boot-admin-starter-client` | |||||
### pom.xml | |||||
```xml | |||||
<?xml version="1.0" encoding="UTF-8"?> | |||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |||||
<modelVersion>4.0.0</modelVersion> | |||||
<artifactId>spring-boot-demo-admin</artifactId> | |||||
<version>0.0.1-SNAPSHOT</version> | |||||
<packaging>war</packaging> | |||||
<name>spring-boot-demo-admin</name> | |||||
<description>Demo project for Spring Boot</description> | |||||
<parent> | |||||
<groupId>com.xkcoding</groupId> | |||||
<artifactId>spring-boot-demo-parent</artifactId> | |||||
<version>0.0.1-SNAPSHOT</version> | |||||
<relativePath>../spring-boot-demo-parent/pom.xml</relativePath> | |||||
</parent> | |||||
<properties> | |||||
<admin.server.version>1.5.2</admin.server.version> | |||||
<admin.server.ui.version>1.5.2</admin.server.ui.version> | |||||
<admin.client.version>1.5.2</admin.client.version> | |||||
</properties> | |||||
<dependencies> | |||||
<dependency> | |||||
<groupId>de.codecentric</groupId> | |||||
<artifactId>spring-boot-admin-server</artifactId> | |||||
<version>${admin.server.version}</version> | |||||
</dependency> | |||||
<dependency> | |||||
<groupId>de.codecentric</groupId> | |||||
<artifactId>spring-boot-admin-server-ui</artifactId> | |||||
<version>${admin.server.ui.version}</version> | |||||
</dependency> | |||||
<dependency> | |||||
<groupId>de.codecentric</groupId> | |||||
<artifactId>spring-boot-admin-starter-client</artifactId> | |||||
<version>${admin.client.version}</version> | |||||
</dependency> | |||||
</dependencies> | |||||
<build> | |||||
<finalName>spring-boot-demo-admin</finalName> | |||||
</build> | |||||
</project> | |||||
``` | |||||
### application.yml | |||||
```yaml | |||||
server: | |||||
port: 8080 | |||||
context-path: /demo | |||||
spring: | |||||
application: | |||||
# 可视化管控台展示的监控项目名,不设置,会使用自动生成的名字 | |||||
name: Spring Boot Admin | |||||
boot: | |||||
admin: | |||||
# 可视化管控台界面的 context-path | |||||
context-path: /spa | |||||
url: http://localhost:${server.port}/${server.context-path} | |||||
jackson: | |||||
serialization: true | |||||
# 去除权限校验 | |||||
endpoints: | |||||
sensitive: false | |||||
``` | |||||
### SpringBootDemoAdminApplication.java | |||||
```java | |||||
@SpringBootApplication | |||||
@EnableAdminServer // 开启管控台 | |||||
@RestController | |||||
public class SpringBootDemoAdminApplication { | |||||
public static void main(String[] args) { | |||||
SpringApplication.run(SpringBootDemoAdminApplication.class, args); | |||||
} | |||||
@GetMapping("/") | |||||
public Map<String, Object> index() { | |||||
ConcurrentMap<String, Object> ret = Maps.newConcurrentMap(); | |||||
ret.put("msg", "Hello Spring Boot Admin"); | |||||
return ret; | |||||
} | |||||
} | |||||
``` | |||||
### 访问 | |||||
http://localhost:8080/demo/spa 即可查看管控台主页,点击项目的 `Detail` 即可查看详细信息,但是比起 `actuator` 提供的端点监控,看起来确实美观不少,但是都各有优缺点。 |
@@ -0,0 +1,48 @@ | |||||
<?xml version="1.0" encoding="UTF-8"?> | |||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |||||
<modelVersion>4.0.0</modelVersion> | |||||
<artifactId>spring-boot-demo-admin</artifactId> | |||||
<version>0.0.1-SNAPSHOT</version> | |||||
<packaging>war</packaging> | |||||
<name>spring-boot-demo-admin</name> | |||||
<description>Demo project for Spring Boot</description> | |||||
<parent> | |||||
<groupId>com.xkcoding</groupId> | |||||
<artifactId>spring-boot-demo-parent</artifactId> | |||||
<version>0.0.1-SNAPSHOT</version> | |||||
<relativePath>../spring-boot-demo-parent/pom.xml</relativePath> | |||||
</parent> | |||||
<properties> | |||||
<admin.server.version>1.5.2</admin.server.version> | |||||
<admin.server.ui.version>1.5.2</admin.server.ui.version> | |||||
<admin.client.version>1.5.2</admin.client.version> | |||||
</properties> | |||||
<dependencies> | |||||
<dependency> | |||||
<groupId>de.codecentric</groupId> | |||||
<artifactId>spring-boot-admin-server</artifactId> | |||||
<version>${admin.server.version}</version> | |||||
</dependency> | |||||
<dependency> | |||||
<groupId>de.codecentric</groupId> | |||||
<artifactId>spring-boot-admin-server-ui</artifactId> | |||||
<version>${admin.server.ui.version}</version> | |||||
</dependency> | |||||
<dependency> | |||||
<groupId>de.codecentric</groupId> | |||||
<artifactId>spring-boot-admin-starter-client</artifactId> | |||||
<version>${admin.client.version}</version> | |||||
</dependency> | |||||
</dependencies> | |||||
<build> | |||||
<finalName>spring-boot-demo-admin</finalName> | |||||
</build> | |||||
</project> |
@@ -0,0 +1,28 @@ | |||||
package com.xkcoding.springbootdemoadmin; | |||||
import com.google.common.collect.Maps; | |||||
import de.codecentric.boot.admin.config.EnableAdminServer; | |||||
import org.springframework.boot.SpringApplication; | |||||
import org.springframework.boot.autoconfigure.SpringBootApplication; | |||||
import org.springframework.web.bind.annotation.GetMapping; | |||||
import org.springframework.web.bind.annotation.RestController; | |||||
import java.util.Map; | |||||
import java.util.concurrent.ConcurrentMap; | |||||
@SpringBootApplication | |||||
@EnableAdminServer // 开启管控台 | |||||
@RestController | |||||
public class SpringBootDemoAdminApplication { | |||||
public static void main(String[] args) { | |||||
SpringApplication.run(SpringBootDemoAdminApplication.class, args); | |||||
} | |||||
@GetMapping("/") | |||||
public Map<String, Object> index() { | |||||
ConcurrentMap<String, Object> ret = Maps.newConcurrentMap(); | |||||
ret.put("msg", "Hello Spring Boot Admin"); | |||||
return ret; | |||||
} | |||||
} |
@@ -0,0 +1,17 @@ | |||||
server: | |||||
port: 8080 | |||||
context-path: /demo | |||||
spring: | |||||
application: | |||||
# 可视化管控台展示的监控项目名,不设置,会使用自动生成的名字 | |||||
name: Spring Boot Admin | |||||
boot: | |||||
admin: | |||||
# 可视化管控台界面的 context-path | |||||
context-path: /spa | |||||
url: http://localhost:${server.port}/${server.context-path} | |||||
jackson: | |||||
serialization: true | |||||
# 去除权限校验 | |||||
endpoints: | |||||
sensitive: false |
@@ -0,0 +1,16 @@ | |||||
package com.xkcoding.springbootdemoadmin; | |||||
import org.junit.Test; | |||||
import org.junit.runner.RunWith; | |||||
import org.springframework.boot.test.context.SpringBootTest; | |||||
import org.springframework.test.context.junit4.SpringRunner; | |||||
@RunWith(SpringRunner.class) | |||||
@SpringBootTest | |||||
public class SpringBootDemoAdminApplicationTests { | |||||
@Test | |||||
public void contextLoads() { | |||||
} | |||||
} |
@@ -40,7 +40,7 @@ | |||||
### application.yml | ### application.yml | ||||
```yml | |||||
```yaml | |||||
server: | server: | ||||
port: 8080 | port: 8080 | ||||
context-path: /demo | context-path: /demo | ||||
@@ -67,7 +67,7 @@ public class SpringBootDemoHelloworldApplication { | |||||
### application.yml | ### application.yml | ||||
```yml | |||||
```yaml | |||||
server: | server: | ||||
port: 8080 | port: 8080 | ||||
context-path: /demo | context-path: /demo | ||||
@@ -58,7 +58,7 @@ public class SpringBootDemoLogbackApplication { | |||||
### application.yml | ### application.yml | ||||
```yml | |||||
```yaml | |||||
server: | server: | ||||
port: 8080 | port: 8080 | ||||
context-path: /demo | context-path: /demo | ||||
@@ -49,7 +49,7 @@ | |||||
### application.yml | ### application.yml | ||||
```yml | |||||
```yaml | |||||
server: | server: | ||||
port: 8080 | port: 8080 | ||||
context-path: /demo | context-path: /demo | ||||
@@ -67,7 +67,7 @@ | |||||
### application.yml | ### application.yml | ||||
```yml | |||||
```yaml | |||||
server: | server: | ||||
port: 8080 | port: 8080 | ||||
context-path: /demo | context-path: /demo | ||||
@@ -15,6 +15,7 @@ | |||||
<module>../spring-boot-demo-helloworld</module> | <module>../spring-boot-demo-helloworld</module> | ||||
<module>../spring-boot-demo-properties</module> | <module>../spring-boot-demo-properties</module> | ||||
<module>../spring-boot-demo-actuator</module> | <module>../spring-boot-demo-actuator</module> | ||||
<module>../spring-boot-demo-admin</module> | |||||
<module>../spring-boot-demo-logback</module> | <module>../spring-boot-demo-logback</module> | ||||
<module>../spring-boot-demo-orm-jpa</module> | <module>../spring-boot-demo-orm-jpa</module> | ||||
<module>../spring-boot-demo-orm-mybatis</module> | <module>../spring-boot-demo-orm-mybatis</module> | ||||
@@ -4,7 +4,7 @@ | |||||
### application.yml | ### application.yml | ||||
```yml | |||||
```yaml | |||||
server: | server: | ||||
port: 8080 | port: 8080 | ||||
context-path: /demo | context-path: /demo | ||||
@@ -45,7 +45,7 @@ | |||||
### application.yml | ### application.yml | ||||
```yml | |||||
```yaml | |||||
server: | server: | ||||
port: 8080 | port: 8080 | ||||
context-path: /demo | context-path: /demo | ||||