StringBoot Admin 2.0

这里用最简单的方式配置

 

一、首先配置Spring Boot Admin Server端:

 

1.1.pom.xml

 

		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>

		
		<dependency>
	            <groupId>de.codecentric</groupId>
	            <artifactId>spring-boot-admin-starter-server</artifactId>
	            <version>2.0.1</version>
	     </dependency>
	
	     <dependency>
	            <groupId>de.codecentric</groupId>
	            <artifactId>spring-boot-admin-server-ui</artifactId>
	            <version>2.0.1</version>
	    </dependency>
		
		<dependency>
		    <groupId>org.springframework.boot</groupId>
		    <artifactId>spring-boot-starter-mail</artifactId>
		</dependency>
		
		
		<dependency>
		    <groupId>org.springframework.boot</groupId>
		    <artifactId>spring-boot-starter-security</artifactId>
		</dependency>

 

 

1.2 启动程序注解配置和安全设置代码:

 

@SpringBootApplication
@EnableAdminServer
@EnableAutoConfiguration
public class MonitoringCenterApplication {

	public static void main(String[] args) {
		SpringApplication.run(MonitoringCenterApplication.class, args);
	}
	

    @Configuration
    public static class SecuritySecureConfig extends WebSecurityConfigurerAdapter {
        private final String adminContextPath;
 
        public SecuritySecureConfig(AdminServerProperties adminServerProperties) {
            this.adminContextPath = adminServerProperties.getContextPath();
        }
 
        @Override
        protected void configure(HttpSecurity http) throws Exception {
            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();
        }
    }
}

 

 

1.3 application.properties配置:

#sping mail
spring.mail.host = smtp.qq.com
spring.mail.username=200239@qq.com
spring.mail.password=xxxxxx
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.enable=true
spring.mail.properties.mail.smtp.starttls.required=true

#管理的实例有启动或关闭时发送邮件
spring.boot.admin.notify.mail.enabled=true
spring.boot.admin.notify.mail.to=200239@qq.com
spring.boot.admin.notify.mail.from=200239@qq.com


#设置监控台用户名密码
spring.security.user.name=admin
spring.security.user.password=admin

 

管理端配置完成,注意,这个的from使用的邮箱账号一定要开启POP3/SMTP服务,密码不是登录密码,是开启pop3分配的密码

 

 

 

二、注册客户端

 

2.1 pom.xml

 

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
	        
	        
	    <dependency>
            <groupId>de.codecentric</groupId>
            <artifactId>spring-boot-admin-starter-client</artifactId>
            <version>2.0.1</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>

 

 

2.2 application.properties

 



server.port=8081

#名称
spring.application.name=message-server
#AdminServer URL路径
spring.boot.admin.client.url=http://127.0.0.1:8080
#如果Admin Server 设置密码这里就要设置对应的密码
spring.boot.admin.client.username=admin
spring.boot.admin.client.password=admin
#使用ip注册,默认是使用主机名
spring.boot.admin.client.instance.prefer-ip=true

#开放所有endpoints
management.endpoints.web.exposure.include=*
management.endpoint.health.show-details=always
#开启Http请求关机
management.endpoint.shutdown.enabled=true
#暴露endpoints的上下文路径
management.endpoints.web.base-path=/message
#暴露endpoints的端口
management.server.port=12345
#ip限制,一般设置内网ip。
management.server.address=127.0.0.1


 

配置完成,启动二个项目即可

 

因为这里配置了:management.endpoints.web.base-path=/message  所以如果要用http调用接口关闭客户端服务时:

POST请求、Content-Type application/json格式  ,只允许本机访问接口。路径为:

http://localhost:12345/message/shutdown

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Spring Boot Admin是用于监控基于Spring Boot的应用程序的工具。它建立在Spring Boot Actuator的基础上,并提供了一个简洁的可视化WEB UI界面。 要搭建Spring Boot Admin,首先需要重启Spring Boot Admin Server和Spring Boot Admin Client应用程序。在Spring Boot启动类上添加@EnableAdminServer注解,并配置application.properties文件。 在Client应用中,需要引入相关依赖,并在配置文件中设置Spring Boot Admin Server的注册地址,并将监控端口暴露给Spring Boot Admin Server访问。 启动测试后,可以通过Spring Boot Admin的WEB UI界面来监控和管理Spring Boot应用程序。 总结起来,Spring Boot Admin是一个用于监控和管理基于Spring Boot的应用程序的工具,通过提供简洁的WEB UI界面,使得对应用程序的监控变得更加方便和直观。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [【SpringBoot框架篇】13.使用springboot admin对springboot应用进行监控](https://blog.csdn.net/ming19951224/article/details/107138845)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *3* [Spring Boot Admin 详解(Spring Boot 2.0,基于 Eureka 的实现)](https://blog.csdn.net/zzg_1990/article/details/84326958)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值