Commit fd2d9a49 authored by yanzg's avatar yanzg

日志只执行1次

parent e2aed704
...@@ -11,7 +11,6 @@ import com.yanzuoguang.util.helper.JsonHelper; ...@@ -11,7 +11,6 @@ import com.yanzuoguang.util.helper.JsonHelper;
import com.yanzuoguang.util.log.Log; import com.yanzuoguang.util.log.Log;
import org.springframework.amqp.core.Message; import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener; import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
...@@ -21,7 +20,7 @@ import org.springframework.stereotype.Component; ...@@ -21,7 +20,7 @@ import org.springframework.stereotype.Component;
* @author 颜佐光 * @author 颜佐光
*/ */
@Component @Component
public class YzgMqConsumer implements InitializingBean { public class YzgMqConsumer {
@Autowired @Autowired
private MqService mqService; private MqService mqService;
...@@ -32,21 +31,6 @@ public class YzgMqConsumer implements InitializingBean { ...@@ -32,21 +31,6 @@ public class YzgMqConsumer implements InitializingBean {
@Autowired @Autowired
private QueueService queueService; private QueueService queueService;
/**
* Invoked by a BeanFactory after it has set all bean properties supplied
* (and satisfied BeanFactoryAware and ApplicationContextAware).
* <p>This method allows the bean instance to perform initialization only
* possible when all bean properties have been set and to throw an
* exception in the event of misconfiguration.
*
* @throws Exception in the event of misconfiguration (such
* as failure to set an essential property) or if initialization fails.
*/
@Override
public void afterPropertiesSet() throws Exception {
yzgMqProcedure.clearLog();
}
/** /**
* MQ回调 * MQ回调
* *
......
...@@ -71,6 +71,7 @@ public class YzgMqProcedure implements InitializingBean { ...@@ -71,6 +71,7 @@ public class YzgMqProcedure implements InitializingBean {
*/ */
@Override @Override
public void afterPropertiesSet() throws Exception { public void afterPropertiesSet() throws Exception {
System.out.println("init");
mqService.createQueue(new QueueVo(YZG_CLEAR_LOG)); mqService.createQueue(new QueueVo(YZG_CLEAR_LOG));
mqService.createQueue(new QueueVo(YZG_MQ_SYSTEM_QUEUE)); mqService.createQueue(new QueueVo(YZG_MQ_SYSTEM_QUEUE));
mqService.createQueue(new QueueVo(YZG_MQ_SYSTEM_QUEUE_PLAN)); mqService.createQueue(new QueueVo(YZG_MQ_SYSTEM_QUEUE_PLAN));
...@@ -95,6 +96,7 @@ public class YzgMqProcedure implements InitializingBean { ...@@ -95,6 +96,7 @@ public class YzgMqProcedure implements InitializingBean {
} }
mqService.createQueue(new QueueVo(getQueueName(item), item.unit, YZG_MQ_SYSTEM_QUEUE_PLAN)); mqService.createQueue(new QueueVo(getQueueName(item), item.unit, YZG_MQ_SYSTEM_QUEUE_PLAN));
} }
this.clearLog();
} }
/** /**
......
...@@ -74,6 +74,21 @@ public class MqServiceImpl implements MqService, InitializingBean { ...@@ -74,6 +74,21 @@ public class MqServiceImpl implements MqService, InitializingBean {
*/ */
private boolean init = false; private boolean init = false;
/**
* Invoked by a BeanFactory after it has set all bean properties supplied
* (and satisfied BeanFactoryAware and ApplicationContextAware).
* <p>This method allows the bean instance to perform initialization only
* possible when all bean properties have been set and to throw an
* exception in the event of misconfiguration.
*
* @throws Exception in the event of misconfiguration (such
* as failure to set an essential property) or if initialization fails.
*/
@Override
public void afterPropertiesSet() throws Exception {
this.init();
}
public synchronized void init() { public synchronized void init() {
if (this.init) { if (this.init) {
return; return;
...@@ -430,19 +445,4 @@ public class MqServiceImpl implements MqService, InitializingBean { ...@@ -430,19 +445,4 @@ public class MqServiceImpl implements MqService, InitializingBean {
return ret; return ret;
} }
} }
/**
* Invoked by a BeanFactory after it has set all bean properties supplied
* (and satisfied BeanFactoryAware and ApplicationContextAware).
* <p>This method allows the bean instance to perform initialization only
* possible when all bean properties have been set and to throw an
* exception in the event of misconfiguration.
*
* @throws Exception in the event of misconfiguration (such
* as failure to set an essential property) or if initialization fails.
*/
@Override
public void afterPropertiesSet() throws Exception {
this.init();
}
} }
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