当前位置:   article > 正文

springboot2.x adminUI监控_spring admin 2.2.x

spring admin 2.2.x

1.server端

pom.xml

  1. <parent>
  2. <groupId>org.springframework.boot</groupId>
  3. <artifactId>spring-boot-starter-parent</artifactId>
  4. <version>2.1.1.RELEASE</version>
  5. <relativePath/>
  6. </parent>
  7. <properties>
  8. <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  9. <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
  10. <java.version>1.8</java.version>
  11. <admin.ui.version>2.1.1</admin.ui.version>
  12. </properties>
  13. <dependencies>
  14. <dependency>
  15. <groupId>de.codecentric</groupId>
  16. <artifactId>spring-boot-admin-server</artifactId>
  17. <version>${admin.ui.version}</version>
  18. </dependency>
  19. <dependency>
  20. <groupId>de.codecentric</groupId>
  21. <artifactId>spring-boot-admin-server-ui</artifactId>
  22. <version>${admin.ui.version}</version>
  23. </dependency>
  24. <dependency>
  25. <groupId>org.springframework.boot</groupId>
  26. <artifactId>spring-boot-starter-web</artifactId>
  27. </dependency>
  28. <dependency>
  29. <groupId>org.springframework.boot</groupId>
  30. <artifactId>spring-boot-starter-mail</artifactId>
  31. </dependency>
  32. <dependency>
  33. <groupId>org.springframework.boot</groupId>
  34. <artifactId>spring-boot-starter-test</artifactId>
  35. <scope>test</scope>
  36. </dependency>
  37. </dependencies>

application.yml

  1. server:
  2. port: 9999
  3. #配置邮件,用于spring boot client项目挂掉后发邮件
  4. spring:
  5. mail:
  6. host: smtp.exmail.qq.com
  7. username: xxx@xxx
  8. password: xxx
  9. default-encoding: UTF-8
  10. properties:
  11. mail:
  12. smtp:
  13. auth: true
  14. starttls:
  15. enable: true
  16. required: true
  17. boot:
  18. admin:
  19. notify:
  20. mail:
  21. from: xxx@xxx
  22. to: xxx@xxx

主启动类:

  1. import de.codecentric.boot.admin.server.config.EnableAdminServer;
  2. import org.springframework.boot.SpringApplication;
  3. import org.springframework.boot.autoconfigure.SpringBootApplication;
  4. @SpringBootApplication
  5. @EnableAdminServer
  6. public class ActuatorApplication {
  7. public static void main(String[] args) {
  8. SpringApplication.run(ActuatorApplication.class, args);
  9. }
  10. }

client端:

  1. <parent>
  2. <groupId>org.springframework.boot</groupId>
  3. <artifactId>spring-boot-starter-parent</artifactId>
  4. <version>2.1.1.RELEASE</version>
  5. <relativePath/> <!-- lookup parent from repository -->
  6. </parent>
  7. <properties>
  8. <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  9. <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
  10. <java.version>1.8</java.version>
  11. <admin.ui.version>2.1.1</admin.ui.version>
  12. </properties>
  13. <dependencies>
  14. <dependency>
  15. <groupId>org.springframework.boot</groupId>
  16. <artifactId>spring-boot-starter-web</artifactId>
  17. </dependency>
  18. <dependency>
  19. <groupId>org.springframework.boot</groupId>
  20. <artifactId>spring-boot-starter-test</artifactId>
  21. <scope>test</scope>
  22. </dependency>
  23. <dependency>
  24. <groupId>de.codecentric</groupId>
  25. <artifactId>spring-boot-admin-starter-client</artifactId>
  26. <version>${admin.ui.version}</version>
  27. </dependency>
  28. </dependencies>

application.properties

  1. server.port=8001
  2. spring.boot.admin.client.url=http://localhost:9999
  3. spring.boot.admin.client.instance.service-url=http://localhost:8001
  4. spring.boot.admin.client.instance.name=client
  5. #关闭安全验证
  6. management.endpoint.beans.enabled=false
  7. management.endpoints.web.exposure.include=*
  8. info.app.name=demo

主启动类:

  1. import org.springframework.boot.SpringApplication;
  2. import org.springframework.boot.autoconfigure.SpringBootApplication;
  3. import org.springframework.scheduling.annotation.EnableScheduling;
  4. import org.springframework.scheduling.annotation.Scheduled;
  5. import org.springframework.web.bind.annotation.RequestMapping;
  6. import org.springframework.web.bind.annotation.RestController;
  7. @SpringBootApplication
  8. @RestController
  9. @EnableScheduling
  10. public class ActuatorClientDemoApplication {
  11. @RequestMapping("/hello")
  12. public String sayHello(String name){
  13. return "hello "+name;
  14. }
  15. @Scheduled(cron="0 0 10,14,16 * * ?")
  16. public void task(){
  17. System.out.println("我执行了....");
  18. }
  19. public static void main(String[] args) {
  20. SpringApplication.run(ActuatorClientDemoApplication.class, args);
  21. }
  22. }

访问:http://localhost:9999/#/applications

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小蓝xlanll/article/detail/102046
推荐阅读
相关标签
  

闽ICP备14008679号