Commit 8bf7320a authored by ag's avatar ag

fix: 修复一个严重错误. 会导致项目无法启动的问题.

parent f6ed221d
......@@ -2,14 +2,11 @@ package cn.quantgroup.tech.shutdown;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.config.RabbitListenerConfigUtils;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.rabbit.listener.RabbitListenerEndpointRegistry;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.Lifecycle;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import org.springframework.context.annotation.Configuration;
import javax.annotation.PreDestroy;
......@@ -19,20 +16,18 @@ import javax.annotation.PreDestroy;
* @author ag
*/
@Slf4j
@Component
@Configuration
public class BaseDestroyHandler {
@Autowired
private ApplicationContext applicationContext;
@PreDestroy
@ConditionalOnBean(RedisTemplate.class)
private void stopRedisSub() {
log.info("我什么都没做, redis stopped");
}
@PreDestroy
@ConditionalOnBean(RabbitTemplate.class)
private void stopRabbitMQ() {
try {
RabbitListenerEndpointRegistry rabbitListenerEndpointRegistry = applicationContext.getBean(
......@@ -40,7 +35,8 @@ public class BaseDestroyHandler {
RabbitListenerEndpointRegistry.class);
rabbitListenerEndpointRegistry.getListenerContainers().forEach(Lifecycle::stop);
} catch (Exception e) {
log.error("貌似停止 MQ 遇到了问题...");
//貌似这段日志不会打印...
log.error("貌似停止 MQ 遇到了问题... 你有MQ么? ");
}
log.info("MQ listener stopped");
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment