mirror of https://github.com/longtai-cn/hippo4j
修复客户端启动后,服务端 30 秒内无法搜索到实例. (#42)
parent
cbaa3a9fe7
commit
d02187d552
@ -0,0 +1,23 @@
|
|||||||
|
package cn.hippo4j.starter.event;
|
||||||
|
|
||||||
|
import org.springframework.context.ApplicationEvent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute after the spring application context is successfully started.
|
||||||
|
*
|
||||||
|
* @author chen.ma
|
||||||
|
* @date 2021/12/25 21:19
|
||||||
|
*/
|
||||||
|
public class ApplicationCompleteEvent extends ApplicationEvent {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new {@code ApplicationEvent}.
|
||||||
|
*
|
||||||
|
* @param source the object on which the event initially occurred or with
|
||||||
|
* which the event is associated (never {@code null})
|
||||||
|
*/
|
||||||
|
public ApplicationCompleteEvent(Object source) {
|
||||||
|
super(source);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,31 @@
|
|||||||
|
package cn.hippo4j.starter.event;
|
||||||
|
|
||||||
|
import org.springframework.context.ApplicationContext;
|
||||||
|
import org.springframework.context.ApplicationListener;
|
||||||
|
import org.springframework.context.event.ContextRefreshedEvent;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Application content post processor.
|
||||||
|
*
|
||||||
|
* @author chen.ma
|
||||||
|
* @date 2021/12/25 20:21
|
||||||
|
*/
|
||||||
|
public class ApplicationContentPostProcessor implements ApplicationListener<ContextRefreshedEvent> {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private ApplicationContext applicationContext;
|
||||||
|
|
||||||
|
private AtomicBoolean executeOnlyOnce = new AtomicBoolean(Boolean.TRUE);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onApplicationEvent(ContextRefreshedEvent event) {
|
||||||
|
if (event.getApplicationContext().getParent() == null && executeOnlyOnce.get()) {
|
||||||
|
applicationContext.publishEvent(new ApplicationCompleteEvent(this));
|
||||||
|
executeOnlyOnce.set(Boolean.FALSE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in new issue