修复 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 org.springframework.context.event.ContextRefreshedEvent;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.concurrent.atomic.AtomicBoolean;
/** /**
* Application content post processor. * Application content post processor.
@ -18,13 +17,15 @@ public class ApplicationContentPostProcessor implements ApplicationListener<Cont
@Resource @Resource
private ApplicationContext applicationContext; private ApplicationContext applicationContext;
private AtomicBoolean executeOnlyOnce = new AtomicBoolean(Boolean.TRUE); private boolean executeOnlyOnce = true;
@Override @Override
public void onApplicationEvent(ContextRefreshedEvent event) { public void onApplicationEvent(ContextRefreshedEvent event) {
if (event.getApplicationContext().getParent() == null && executeOnlyOnce.get()) { synchronized (ApplicationContentPostProcessor.class) {
if (executeOnlyOnce) {
applicationContext.publishEvent(new ApplicationCompleteEvent(this)); applicationContext.publishEvent(new ApplicationCompleteEvent(this));
executeOnlyOnce.set(Boolean.FALSE); executeOnlyOnce = false;
}
} }
} }

Loading…
Cancel
Save