开发Spring Boot Admin
Core Annotation
package tech.foolfish.monitor;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import de.codecentric.boot.admin.server.config.EnableAdminServer;
@SpringBootApplication
@EnableDiscoveryClient
@EnableScheduling
@EnableAdminServer
public class MicroserviceMonitorBootadminApplication {
public static void main(String[] args) {
SpringApplication.run(MicroserviceMonitorBootadminApplication.class, args);
}
@Configuration
public static class SecurityPermitAllConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().anyRequest().permitAll()
.and().csrf().disable();
}
}
}
application.yml
server:
port: 8099
spring:
application:
name: monitor-bootadmin
eureka:
instance:
leaseRenewalIntervalInSeconds: 10
health-check-url-path: /actuator/health
metadata-map:
startup: ${random.int} #needed to trigger info and endpoint update after restart
client:
registryFetchIntervalSeconds: 5
serviceUrl:
defaultZone: ${EUREKA_SERVICE_URL:http://localhost:8761}/eureka/
management:
endpoints:
web:
exposure:
include: '*'
endpoint:
health:
show-details: ALWAYS
pom.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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.10</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>tech.foolfish</groupId>
<artifactId>microservice-monitor-bootadmin</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>microservice-monitor-bootadmin</name>
<description>Monitor Bootadmin</description>
<properties>
<java.version>11</java.version>
<spring-boot-admin.version>2.6.8</spring-boot-admin.version>
<spring-cloud.version>2021.0.3</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-dependencies</artifactId>
<version>${spring-boot-admin.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
部署Spring Boot Admin
xuej@dev-server:~/Documents/sts4/microservice-monitor-bootadmin$ mvn clean package -DskipTests=true
xuej@dev-server:~/Documents/sts4/microservice-monitor-bootadmin$ java -jar target/microservice-monitor-bootadmin-0.0.1-SNAPSHOT.jar
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.6.10)
2022-08-06 04:27:05.249 INFO 15957 --- [ main] .MicroserviceMonitorBootadminApplication : Starting MicroserviceMonitorBootadminApplication v0.0.1-SNAPSHOT using Java 11.0.11 on dev-server with PID 15957 (/home/xuej/Documents/sts4/microservice-monitor-bootadmin/target/microservice-monitor-bootadmin-0.0.1-SNAPSHOT.jar started by xuej in /home/xuej/Documents/sts4/microservice-monitor-bootadmin)
2022-08-06 04:27:05.268 INFO 15957 --- [ main] .MicroserviceMonitorBootadminApplication : No active profile set, falling back to 1 default profile: "default"
2022-08-06 04:27:06.773 INFO 15957 --- [ main] o.s.cloud.context.scope.GenericScope : BeanFactory id=7d3f4c59-b867-3659-831e-f874b1b86498
2022-08-06 04:27:06.892 INFO 15957 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.cloud.client.loadbalancer.reactive.LoadBalancerBeanPostProcessorAutoConfiguration' of type [org.springframework.cloud.client.loadbalancer.reactive.LoadBalancerBeanPostProcessorAutoConfiguration] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2022-08-06 04:27:06.895 INFO 15957 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.cloud.client.loadbalancer.reactive.LoadBalancerBeanPostProcessorAutoConfiguration$ReactorDeferringLoadBalancerFilterConfig' of type [org.springframework.cloud.client.loadbalancer.reactive.LoadBalancerBeanPostProcessorAutoConfiguration$ReactorDeferringLoadBalancerFilterConfig] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2022-08-06 04:27:06.897 INFO 15957 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'reactorDeferringLoadBalancerExchangeFilterFunction' of type [org.springframework.cloud.client.loadbalancer.reactive.DeferringLoadBalancerExchangeFilterFunction] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2022-08-06 04:27:07.267 INFO 15957 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8099 (http)
2022-08-06 04:27:07.287 INFO 15957 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2022-08-06 04:27:07.287 INFO 15957 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.65]
2022-08-06 04:27:07.439 INFO 15957 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2022-08-06 04:27:07.439 INFO 15957 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 2068 ms
2022-08-06 04:27:08.339 WARN 15957 --- [ main] ion$DefaultTemplateResolverConfiguration : Cannot find template location: classpath:/templates/ (please add some templates or check your Thymeleaf configuration)
2022-08-06 04:27:08.852 INFO 15957 --- [ main] DiscoveryClientOptionalArgsConfiguration : Eureka HTTP Client uses RestTemplate.
2022-08-06 04:27:09.355 WARN 15957 --- [ main] .s.s.UserDetailsServiceAutoConfiguration :
Using generated security password: e219d029-d639-4712-92ca-9827f8c037ea
This generated password is for development use only. Your security configuration must be updated before running your application in production.
2022-08-06 04:27:09.460 INFO 15957 --- [ main] o.s.s.web.DefaultSecurityFilterChain : Will secure any request with [org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter@4e6f2bb5, org.springframework.security.web.context.SecurityContextPersistenceFilter@5833f5cd, org.springframework.security.web.header.HeaderWriterFilter@23592946, org.springframework.security.web.authentication.logout.LogoutFilter@71f0b72e, org.springframework.security.web.savedrequest.RequestCacheAwareFilter@23f3dbf0, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter@aa149ed, org.springframework.security.web.authentication.AnonymousAuthenticationFilter@21e20ad5, org.springframework.security.web.session.SessionManagementFilter@7a2b1eb4, org.springframework.security.web.access.ExceptionTranslationFilter@205bed61, org.springframework.security.web.access.intercept.FilterSecurityInterceptor@497aec8c]
2022-08-06 04:27:09.560 WARN 15957 --- [ main] iguration$LoadBalancerCaffeineWarnLogger : Spring Cloud LoadBalancer is currently working with the default cache. While this cache implementation is useful for development and tests, it's recommended to use Caffeine cache in production.You can switch to using Caffeine cache, by adding it and org.springframework.cache.caffeine.CaffeineCacheManager to the classpath.
2022-08-06 04:27:09.569 INFO 15957 --- [ main] o.s.b.a.e.web.EndpointLinksResolver : Exposing 16 endpoint(s) beneath base path '/actuator'
2022-08-06 04:27:09.632 INFO 15957 --- [ main] o.s.c.n.eureka.InstanceInfoFactory : Setting initial instance status as: STARTING
2022-08-06 04:27:09.740 INFO 15957 --- [ main] com.netflix.discovery.DiscoveryClient : Initializing Eureka in region us-east-1
2022-08-06 04:27:09.751 INFO 15957 --- [ main] c.n.d.s.r.aws.ConfigClusterResolver : Resolving eureka endpoints via configuration
2022-08-06 04:27:09.788 INFO 15957 --- [ main] com.netflix.discovery.DiscoveryClient : Disable delta property : false
2022-08-06 04:27:09.789 INFO 15957 --- [ main] com.netflix.discovery.DiscoveryClient : Single vip registry refresh property : null
2022-08-06 04:27:09.789 INFO 15957 --- [ main] com.netflix.discovery.DiscoveryClient : Force full registry fetch : false
2022-08-06 04:27:09.789 INFO 15957 --- [ main] com.netflix.discovery.DiscoveryClient : Application is null : false
2022-08-06 04:27:09.789 INFO 15957 --- [ main] com.netflix.discovery.DiscoveryClient : Registered Applications size is zero : true
2022-08-06 04:27:09.789 INFO 15957 --- [ main] com.netflix.discovery.DiscoveryClient : Application version is -1: true
2022-08-06 04:27:09.790 INFO 15957 --- [ main] com.netflix.discovery.DiscoveryClient : Getting all instance registry info from the eureka server
2022-08-06 04:27:10.500 INFO 15957 --- [ main] com.netflix.discovery.DiscoveryClient : The response status is 200
2022-08-06 04:27:10.505 INFO 15957 --- [ main] com.netflix.discovery.DiscoveryClient : Starting heartbeat executor: renew interval is: 10
2022-08-06 04:27:10.508 INFO 15957 --- [ main] c.n.discovery.InstanceInfoReplicator : InstanceInfoReplicator onDemand update allowed rate per min is 4
2022-08-06 04:27:10.518 INFO 15957 --- [ main] com.netflix.discovery.DiscoveryClient : Discovery Client initialized at timestamp 1659731230516 with initial instances count: 2
2022-08-06 04:27:10.520 INFO 15957 --- [ main] o.s.c.n.e.s.EurekaServiceRegistry : Registering application MONITOR-BOOTADMIN with eureka with status UP
2022-08-06 04:27:10.522 INFO 15957 --- [ main] com.netflix.discovery.DiscoveryClient : Saw local status change event StatusChangeEvent [timestamp=1659731230521, current=UP, previous=STARTING]
2022-08-06 04:27:10.525 INFO 15957 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_MONITOR-BOOTADMIN/10.0.2.15:monitor-bootadmin:8099: registering service...
2022-08-06 04:27:10.676 INFO 15957 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_MONITOR-BOOTADMIN/10.0.2.15:monitor-bootadmin:8099 - registration status: 204
2022-08-06 04:27:10.855 INFO 15957 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8099 (http) with context path ''
2022-08-06 04:27:10.856 INFO 15957 --- [ main] .s.c.n.e.s.EurekaAutoServiceRegistration : Updating port to 8099
2022-08-06 04:27:10.924 INFO 15957 --- [ main] .MicroserviceMonitorBootadminApplication : Started MicroserviceMonitorBootadminApplication in 6.292 seconds (JVM running for 6.954)
2022-08-06 04:27:15.640 INFO 15957 --- [nio-8099-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet'
2022-08-06 04:27:15.641 INFO 15957 --- [nio-8099-exec-1] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'
2022-08-06 04:27:15.642 INFO 15957 --- [nio-8099-exec-1] o.s.web.servlet.DispatcherServlet : Completed initialization in 1 ms
部署效果展示
