com.turingoal.cms.core.filter.SystemInitListener.java Source code

Java tutorial

Introduction

Here is the source code for com.turingoal.cms.core.filter.SystemInitListener.java

Source

package com.turingoal.cms.core.filter;

import javax.servlet.ServletContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.web.context.ServletContextAware;
import com.turingoal.common.license.TgLicenseChcker;

/**
 * ??
 */
public class SystemInitListener implements ApplicationListener<ContextRefreshedEvent>, ServletContextAware {
    private final Logger log = LoggerFactory.getLogger(SystemInitListener.class);
    private ServletContext application;
    @Value("#{applicationProperties['security.openValidateCaptchaCode']}")
    private Boolean openValidateCaptchaCode; // ????
    @Value("#{applicationProperties['security.openValidateCaptchaCode4admin']}")
    private Boolean openValidateCaptchaCode4admin; // ??????

    /**
     * SpringBean???
     */
    @Override
    public void onApplicationEvent(final ContextRefreshedEvent event) {
        // web spring mvcroot application context ,? contextroot application context? ??onApplicationEvent???????root application context?????????
        if (event.getApplicationContext().getParent() == null) {
            log.info("************[{}]??!************", application.getServletContextName());
            // license
            TgLicenseChcker.checkInit(application, SystemInitListener.class);
            // ????
            application.setAttribute("openValidateCaptchaCode", openValidateCaptchaCode);
            // ??????
            application.setAttribute("openValidateCaptchaCode4admin", openValidateCaptchaCode4admin);
        }
    }

    @Override
    public void setServletContext(final ServletContext servletContext) {
        this.application = servletContext;
    }
}