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

io.github.luyiisme.script.spring.ApplicationContextAwareScriptInvokeInterceptor Maven / Gradle / Ivy

package io.github.luyiisme.script.spring;

import java.util.Map;

import io.github.luyiisme.script.api.ScriptInvokeInterceptor;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

/**
 * make spring application context available from script invocation;
 *
 * @author: [email protected]
 * @create: 2020-04-20 17:24
 **/
public class ApplicationContextAwareScriptInvokeInterceptor implements ScriptInvokeInterceptor,
    ApplicationContextAware {
    public static final String APPLICATION_CONTEXT_KEY = "applicationContext";
    private ApplicationContext applicationContext;

    @Override
    public void preHandle(String scriptName, Object scriptInstance, Map scriptInvocationParams)
        throws Exception {
        if (applicationContext == null) { return; }
        scriptInvocationParams.put(APPLICATION_CONTEXT_KEY, applicationContext);
        return;
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy