让Discord客户端惰性启动

This commit is contained in:
2025-08-28 15:22:30 +08:00
parent eab8314720
commit 6a9d697f6e
2 changed files with 4 additions and 1 deletions
@@ -14,6 +14,7 @@ import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
@@ -29,7 +30,7 @@ import java.util.Map;
@RestController @RestController
@RequestMapping("/message") @RequestMapping("/message")
class Message { class Message {
@Autowired GatewayDiscordClient DiscordBotClient; @Lazy @Autowired GatewayDiscordClient DiscordBotClient;
@Autowired List<String> ApiKeyList; @Autowired List<String> ApiKeyList;
@Schema(description = "包含了发送消息的数据包") @Schema(description = "包含了发送消息的数据包")
@@ -5,6 +5,7 @@ import discord4j.core.GatewayDiscordClient;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.RandomStringUtils; import org.apache.commons.lang3.RandomStringUtils;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.io.IOException; import java.io.IOException;
@@ -17,6 +18,7 @@ import java.util.List;
@Component @Component
class GlobalSharedBean { class GlobalSharedBean {
@Lazy
@Bean @Bean
GatewayDiscordClient GetDiscordClient(){ GatewayDiscordClient GetDiscordClient(){
String DiscordBotToken = System.getenv("Discord_Bot_Token"); String DiscordBotToken = System.getenv("Discord_Bot_Token");