zhuangjinxin / spring-boot-learn

Spring Boot 学习总结
1 stars 0 forks source link

[Spring Boot 简易笔记]Spring Boot Admin #4

Open zhuangjinxin opened 6 years ago

zhuangjinxin commented 6 years ago

基础配置

Spring Boot Admin Server:

1.添加依赖:

compile group: 'de.codecentric', name: 'spring-boot-admin-server', version: '1.5.6'
compile group: 'de.codecentric', name: 'spring-boot-admin-server-ui', version: '1.5.6'

2.添加注解: 在启动类上添加 @EnableAdminServer注解;

3.浏览器访问http://localhost:8080;

Spring Boot Admin Client:

1.添加依赖

compile group: 'de.codecentric', name: 'spring-boot-admin-starter-client', version: '1.5.6'

2.添加配置:

server.port=8081
spring.boot.admin.url=http://localhost:8080
management.security.enabled=false

启动和关停Client,浏览器有提示。

安全设置(拓展)

Admin Server端:

1.添加依赖:

compile group: 'de.codecentric', name: 'spring-boot-admin-server-ui-login', version: '1.5.6'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-security', version: '1.5.9.RELEASE'

2.自定义配置:

@Configuration
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.formLogin().loginPage("/login.html").loginProcessingUrl("/login").permitAll();
        http.logout().logoutUrl("/logout");
        http.csrf().disable();
        http.authorizeRequests().antMatchers("/login.html", "/**/*.css", "/img/**", "/third-party/**").permitAll();
        http.authorizeRequests().antMatchers("/**").authenticated();
        http.httpBasic();
    }
}

3.添加配置:

security.user.name=admin
security.user.password=admin

Admin Client端:

在配置文件中添加:

#These two are needed so that the client can register at the protected server api
spring.boot.admin.username=admin
spring.boot.admin.password=admin
#These two are needed so that the server can access the proteceted client endpoints
spring.boot.admin.client.metadata.user.name=admin
spring.boot.admin.client.metadata.user.password=admin

重启Admin Server端和Client端,输入密码即可访问查看!

邮件配置

在Server端: 1.添加依赖:

compile group: 'org.springframework.boot', name: 'spring-boot-starter-mail', version: '1.5.9.RELEASE'

2.添加配置:

spring.mail.host=smtp-mail.outlook.com
spring.mail.username=zhuangjinxin@hotmail.com
spring.mail.password=******
spring.boot.admin.notify.mail.to=zhuangjinxin@outlook.com

参考链接:

  1. A Guide to Spring Boot Admin http://www.baeldung.com/spring-boot-admin
  2. A Look at Spring Boot Admin https://dzone.com/articles/a-look-at-spring-boot-admin
zhuangjinxin commented 6 years ago

Gradle添加完依赖之后报错:

Project resolve errors
Warning:<i><b>root project 'spring-boot': Unable to resolve additional project configuration.</b>
Details: org.gradle.api.internal.artifacts.ivyservice.DefaultLenientConfiguration$ArtifactResolveException: Could not resolve all files for configuration ':compileClasspath'.
Caused by: org.gradle.internal.resolve.ArtifactResolveException: Could not download guava.jar (com.google.guava:guava:14.0.1)
Caused by: org.gradle.api.resources.ResourceException: Could not get resource 'https://repo.maven.apache.org/maven2/com/google/guava/guava/14.0.1/guava-14.0.1.jar'.
Caused by: java.net.SocketTimeoutException: Read timed out</i>
Warning:<i><b>root project 'spring-boot': Unable to resolve additional project configuration.</b>
Details: org.gradle.api.artifacts.ResolveException: Could not resolve all dependencies for configuration ':compileClasspath'.
Caused by: org.gradle.internal.resolve.ArtifactResolveException: Could not download guava.jar (com.google.guava:guava:14.0.1)
Caused by: org.gradle.api.resources.ResourceException: Could not get resource 'https://repo.maven.apache.org/maven2/com/google/guava/guava/14.0.1/guava-14.0.1.jar'.
Caused by: java.net.SocketTimeoutException: Read timed out</i>
zhuangjinxin commented 6 years ago

spring-boot-application (e34430a9)>Trace 页面报错提示:

Error: {"timestamp":1516851689456,"status":401,"error":"Unauthorized","message":"Full authentication is required to access this resource.","path":"/trace"}
zhuangjinxin commented 6 years ago

spring-boot-application (e34430a9)>Logging页面报错提示:

Error:{"error": "Couldn't find Logback JMXConfigurator-MBean"}
zhuangjinxin commented 6 years ago

Spring Boot Client 端 : 如果management.security.enabled=true,Admin UI 只显示Client的状态(Status only)。

zhuangjinxin commented 6 years ago

关停Client,Admin发送邮件时报错:

2018-01-25 12:49:23.469 ERROR 8225 --- [    updateTask1] d.c.boot.admin.notify.MailNotifier       : Couldn't notify for event de.codecentric.boot.admin.event.ClientApplicationStatusChangedEvent@a01ffe35 

org.springframework.mail.MailSendException: Failed messages: com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.57 SMTP; Client was not authenticated to send anonymous mail during MAIL FROM [HK2PR0302CA0002.apcprd03.prod.outlook.com]
javax.mail.AuthenticationFailedException: 535 5.7.3 Authentication unsuccessful [HK2P15301CA0008.APCP153.PROD.OUTLOOK.COM]