使用 Spring Boot Admin 管理 Spring Boot 应用
Spring Boot Spring Boot Admin About 2,676 wordsclient 使用了主机名注册
client actuator使用了hostname进行注册时无法绑定到Spring Boot Admin,可设置prefer-ip
属性为true
即可解决。
spring:
boot:
admin:
client:
url: http://localhost:12345
instance:
prefer-ip: true
设置邮件提醒
Spring Boot Admin Server中设置client下线通知
- 添加
spring-boot-starter-mail
依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
- 设置admin发/收件人
spring:
boot:
admin:
notify:
mail:
from: ${spring.mail.username}
to: receiver@163.com
mail:
host: smtp.163.com
username: username@163.com
password: # your own password
535 Error: authentication failed
- 网易邮箱有没有开启授权码,若开启则password为授权码
- username需是完整的登录名,如:15317832520@163.com
553 Mail from must equal authorized user
必须设置spring.boot.admin.notify.mail.from
属性,默认是Spring Boot Admin <noreply@localhost>
。
spring:
boot:
admin:
notify:
mail:
from: ${spring.mail.username}
mail:
username: 15317832520@163.com
Spring Boot Admin添加登录页面
- 添加
spring-boot-starter-security
依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
- 设置用户名密码
spring:
security:
user:
name: admin
password: admin123
- 配置Spring Boot Admin登录页面
@Configuration
public 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
}
}
参考
https://codecentric.github.io/spring-boot-admin/current/
代码
https://github.com/fendoudebb/learning/tree/master/java/learn-spring-boot-admin
Views: 2,775 · Posted: 2019-08-01
————        END        ————
Give me a Star, Thanks:)
https://github.com/fendoudebb/LiteNote扫描下方二维码关注公众号和小程序↓↓↓
Loading...