本文共 4724 字,大约阅读时间需要 15 分钟。
SpringBootAdmin 是一个开源项目,用来监控 SpringBoot 应用,SpringBootAdmin 客户端可以整合 SpringCloud ,通过集成 Eureka 进行微服务的监控。本教程基于最新版本 2.2.0, 提供了汉化等功能。
父类 pom 文件,基于 Spring Cloud Hoxton.RELEASE 版本
1.8 Hoxton.RELEASE
de.codecentric spring-boot-admin-starter-client 2.2.0 org.springframework.boot spring-boot-starter-web org.springframework.cloud spring-cloud-starter-netflix-eureka-client org.springframework.boot spring-boot-starter-webflux
org.springframework.cloud spring-cloud-dependencies ${spring-cloud.version} pom import
org.springframework.cloud spring-cloud-starter-netflix-eureka-server org.springframework.boot spring-boot-starter
spring: application: name: eureka-serverserver: port: 8761eureka: client: service-url: defaultZone: http://localhost:8761/eureka register-with-eureka: false fetch-registry: falsemanagement: endpoints: web: exposure: include: "*" endpoint: health: show-details: ALWAYS
@SpringBootApplication@EnableEurekaServerpublic class EurekaServerApplication { public static void main(String[] args) { SpringApplication.run(EurekaServerApplication.class, args); }}
org.springframework.boot spring-boot-starter-security org.springframework.boot spring-boot-starter-mail de.codecentric spring-boot-admin-starter-server 2.2.0
spring: application: name: admin-server security: user: name: "admin" password: "admin"server: port: 8769eureka: client: registryFetchIntervalSeconds: 5 service-url: defaultZone: ${EUREKA_SERVICE_URL:http://localhost:8761}/eureka/ instance: leaseRenewalIntervalInSeconds: 10 health-check-url-path: /actuator/health metadata-map: user.name: ${spring.security.user.name} user.password: ${spring.security.user.password}management: endpoints: web: exposure: include: "*" endpoint: health: show-details: ALWAYS
集成 Spring Security 提供登录权限
@Configurationpublic class SecuritySecureConfig extends WebSecurityConfigurerAdapter { private final String adminContextPath; public SecuritySecureConfig(AdminServerProperties adminServerProperties) { this.adminContextPath = adminServerProperties.getContextPath(); } @Override protected void configure(HttpSecurity http) throws Exception { // @formatter:off SavedRequestAwareAuthenticationSuccessHandler successHandler = new SavedRequestAwareAuthenticationSuccessHandler(); successHandler.setTargetUrlParameter( "redirectTo" ); http.authorizeRequests() .antMatchers( adminContextPath + "/assets/**" ).permitAll() .antMatchers( adminContextPath + "/login" ).permitAll() .anyRequest().authenticated() .and() .formLogin().loginPage( adminContextPath + "/login" ).successHandler( successHandler ).and() .logout().logoutUrl( adminContextPath + "/logout" ).and() .httpBasic().and() .csrf().disable(); // @formatter:on }}
@SpringBootApplication@EnableAdminServer@EnableEurekaClientpublic class AdminServerApplication { public static void main(String[] args) { SpringApplication.run(AdminServerApplication.class, args); }}
spring: application: name: admin-client4server: port: 8764eureka: client: registryFetchIntervalSeconds: 5 service-url: defaultZone: ${EUREKA_SERVICE_URL:http://localhost:8761}/eureka/ instance: leaseRenewalIntervalInSeconds: 10 health-check-url-path: /actuator/healthmanagement: endpoints: web: exposure: include: "*" endpoint: health: show-details: ALWAYS
@SpringBootApplication@EnableEurekaClientpublic class AdminClientApplication { public static void main(String[] args) { SpringApplication.run(AdminClientApplication.class, args); }}—— 完
公众号:【星尘Pro】
github:
推荐阅读
https://blog.csdn.net/forezp/article/details/86105850
https://codecentric.github.io/spring-boot-admin/2.2.0/ https://github.com/codecentric/spring-boot-admin