修复 spring 上下文容器无法执行问题.

pull/84/head
chen.ma 3 years ago
parent f09403ba9a
commit 71484948c8

@ -5,7 +5,6 @@ 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.
@ -18,13 +17,15 @@ public class ApplicationContentPostProcessor implements ApplicationListener<Cont
@Resource
private ApplicationContext applicationContext;
private AtomicBoolean executeOnlyOnce = new AtomicBoolean(Boolean.TRUE);
private boolean executeOnlyOnce = true;
@Override
public void onApplicationEvent(ContextRefreshedEvent event) {
if (event.getApplicationContext().getParent() == null && executeOnlyOnce.get()) {
applicationContext.publishEvent(new ApplicationCompleteEvent(this));
executeOnlyOnce.set(Boolean.FALSE);
synchronized (ApplicationContentPostProcessor.class) {
if (executeOnlyOnce) {
applicationContext.publishEvent(new ApplicationCompleteEvent(this));
executeOnlyOnce = false;
}
}
}

Loading…
Cancel
Save