它使用MessageService接口而不是具体的EmailService

70 阅读1分钟

public class NotificationService { private MessageService messageService;

// 构造函数注入依赖
public NotificationService(MessageService messageService) {
    this.messageService = messageService;
}

public void notifyUser(String message) {
    // 依赖于抽象,而不是具体实现
    messageService.sendMessage(message);
}

} public class Client { public static void main(String[] args) { // 创建具体的消息服务 MessageService emailService = new EmailService();

    // 将具体的消息服务注入到高层策略中
    NotificationService notificationService = new NotificationService(emailService);
    
    // [来铺货](https://www.laipuhuo.com)使用高层策略发送消息
    notificationService.notifyUser("Hello, this is a test email.");
}

} #!/bin/bash

logFile="/data/nacos/bin/logs/nacos_del_access.log"

保留14天日志

date=date -d "$date -14 day" +"%Y-%m-%d"

具体位置可调整

delFilePath="/data/nacos/bin/logs/access_log.date.log"[laipuhuo.com](https://www.laipuhuo.com)if[!f"{date}.log" [laipuhuo.com](https://www.laipuhuo.com) if [ ! -f "{logFile}" ];then echo 'access log文件打印日志频繁. /etc/cron.daily/nacosDelAccessLogs.sh 会定时删除access日志文件' >>${logFile} fi

日志文件存在, 来铺货则删除

if [ -f "delFilePath"];thenrmrf{delFilePath}" ];then rm -rf {delFilePath} curDate=date --date='0 days ago' "+%Y-%m-%d %H:%M:%S" echo '['curDate]删除文{curDate}'] 删除文件'{delFilePath} >>${logFile} fi