All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.biz.common.application.aware.ApplicationContextAwareUtils Maven / Gradle / Ivy

Go to download

BizX 是一个灵活而高效的业务开发框架, 其中也有很多为业务开发所需要的工具类的提供。

The newest version!
package com.biz.common.application.aware;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;


/**
 * 封装 ApplicationContext 的基本用法
 *
 * @author francis
 */
@Slf4j
@Order(Ordered.HIGHEST_PRECEDENCE)
public class ApplicationContextAwareUtils implements ApplicationContextAware {

    private static volatile ApplicationContext applicationContext;

    private ApplicationContextAwareUtils() {
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        if (applicationContext == null) {
            if (log.isDebugEnabled()) {
                log.error("试图设置一个空的ApplicationContext");
            }
            throw new IllegalArgumentException("applicationContext不能为null");
        }
        if (ApplicationContextAwareUtils.applicationContext != null) {
            log.warn("ApplicationContext已经被设置,此次设置将覆盖之前的实例");
        }
        ApplicationContextAwareUtils.applicationContext = applicationContext;
    }

    /**
     * 获取 ApplicationContext
     *
     * @return
     */
    public static ApplicationContext getApplicationContext() {
        return applicationContext;
    }


}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy