扫描二维码下载沐宇APP

沐宇

微信扫码使用沐宇小程序

沐宇

SpringBoot Admin 濡備綍闆嗘垚閫氱煡鏈嶅姟

扬州沐宇科技
2024-06-15 20:01:01
springboot

SpringBoot Admin鍙互閫氳繃闆嗘垚閭欢銆丼lack銆丠ipChat銆丮icrosoft Teams绛夐€氱煡鏈嶅姟鏉ュ疄鐜伴€氱煡鍔熻兘銆備笅闈互闆嗘垚閭欢閫氱煡涓轰緥杩涜璇存槑锛?/p>

  1. 娣诲姞渚濊禆锛氬湪pom.xml鏂囦欢涓坊鍔燬pring Boot Admin Server鐨勪緷璧栧拰Spring Boot Starter Mail鐨勪緷璧栥€?/li>
<dependency>
    <groupId>de.codecentric</groupId>
    <artifactId>spring-boot-admin-starter-server</artifactId>
    <version>2.5.1</version>
</dependency>

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-mail</artifactId>
</dependency>
  1. 閰嶇疆閭欢閫氱煡锛氬湪application.properties鏂囦欢涓厤缃偖浠堕€氱煡鐨勭浉鍏充俊鎭紝濡係MTP鏈嶅姟鍣ㄣ€佸彂浠朵汉閭銆佹敹浠朵汉閭绛夈€?/li>
spring.mail.host=smtp.example.com
spring.mail.port=587
spring.mail.username=your-email@example.com
spring.mail.password=your-email-password
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.to=admin@example.com
spring.boot.admin.notify.mail.from=your-email@example.com
  1. 鍚敤閭欢閫氱煡锛氬湪Spring Boot Admin Server鐨勯厤缃被涓坊鍔燖EnableAdminServer鍜孈EnableScheduling娉ㄨВ锛屽苟閰嶇疆@EnableAdminServer.notifyMail()銆?/li>
import de.codecentric.boot.admin.server.config.EnableAdminServer;
import org.springframework.boot.autoconfigure.mail.MailProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.mail.javamail.JavaMailSender;

@Configuration
@EnableAdminServer
public class AdminServerConfig {

    @Bean
    public NotifyMailNotifier notifyMailNotifier(JavaMailSender mailSender, MailProperties mailProperties) {
        return new NotifyMailNotifier(mailSender, mailProperties);
    }

}

閫氳繃浠ヤ笂姝ラ锛屽氨鍙互瀹炵幇SpringBoot Admin闆嗘垚閭欢閫氱煡鏈嶅姟銆傚叾浠栭€氱煡鏈嶅姟鐨勯泦鎴愭柟娉曠被浼硷紝鍙渶鏍规嵁鍏蜂綋鏈嶅姟鐨勯厤缃姹傝繘琛岀浉搴旂殑閰嶇疆鍗冲彲銆?/p>

扫码添加客服微信