Commit 8bf7320a authored by ag's avatar ag

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

parent f6ed221d
...@@ -2,14 +2,11 @@ package cn.quantgroup.tech.shutdown; ...@@ -2,14 +2,11 @@ package cn.quantgroup.tech.shutdown;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.config.RabbitListenerConfigUtils; import org.springframework.amqp.rabbit.config.RabbitListenerConfigUtils;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.rabbit.listener.RabbitListenerEndpointRegistry; import org.springframework.amqp.rabbit.listener.RabbitListenerEndpointRegistry;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.context.Lifecycle; import org.springframework.context.Lifecycle;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import javax.annotation.PreDestroy; import javax.annotation.PreDestroy;
...@@ -19,20 +16,18 @@ import javax.annotation.PreDestroy; ...@@ -19,20 +16,18 @@ import javax.annotation.PreDestroy;
* @author ag * @author ag
*/ */
@Slf4j @Slf4j
@Component @Configuration
public class BaseDestroyHandler { public class BaseDestroyHandler {
@Autowired @Autowired
private ApplicationContext applicationContext; private ApplicationContext applicationContext;
@PreDestroy @PreDestroy
@ConditionalOnBean(RedisTemplate.class)
private void stopRedisSub() { private void stopRedisSub() {
log.info("我什么都没做, redis stopped"); log.info("我什么都没做, redis stopped");
} }
@PreDestroy @PreDestroy
@ConditionalOnBean(RabbitTemplate.class)
private void stopRabbitMQ() { private void stopRabbitMQ() {
try { try {
RabbitListenerEndpointRegistry rabbitListenerEndpointRegistry = applicationContext.getBean( RabbitListenerEndpointRegistry rabbitListenerEndpointRegistry = applicationContext.getBean(
...@@ -40,7 +35,8 @@ public class BaseDestroyHandler { ...@@ -40,7 +35,8 @@ public class BaseDestroyHandler {
RabbitListenerEndpointRegistry.class); RabbitListenerEndpointRegistry.class);
rabbitListenerEndpointRegistry.getListenerContainers().forEach(Lifecycle::stop); rabbitListenerEndpointRegistry.getListenerContainers().forEach(Lifecycle::stop);
} catch (Exception e) { } catch (Exception e) {
log.error("貌似停止 MQ 遇到了问题..."); //貌似这段日志不会打印...
log.error("貌似停止 MQ 遇到了问题... 你有MQ么? ");
} }
log.info("MQ listener stopped"); 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