StringBoot Admin 2.0

博客介绍了Spring Boot Admin的配置方法。先配置Server端,包括pom.xml、启动程序注解和安全设置代码、application.properties,管理端邮箱要开启POP3/SMTP服务。接着注册客户端,配置pom.xml和application.properties。最后提到用http调用接口关闭客户端服务的相关设置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

这里用最简单的方式配置

 

一、首先配置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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值