Search in sources :

Example 1 with DynamicSpringContextLoader

use of com.alipay.sofa.isle.loader.DynamicSpringContextLoader in project sofa-boot by alipay.

the class BeanHierarchyTest method refreshApplication.

private void refreshApplication(ApplicationRuntimeModel application) throws Exception {
    DefaultListableBeanFactory rootBeanFactory = new DefaultListableBeanFactory();
    ConfigurableApplicationContext rootApplicationContext = new GenericApplicationContext(rootBeanFactory);
    rootApplicationContext.refresh();
    SofaModuleProperties sofaModuleProperties = new SofaModuleProperties();
    sofaModuleProperties.setBeanLoadCost(1);
    rootBeanFactory.registerSingleton("sofaModuleProperties", sofaModuleProperties);
    rootBeanFactory.registerSingleton(SofaBootConstants.PROCESSORS_OF_ROOT_APPLICATION_CONTEXT, new HashMap<>());
    SpringContextLoader springContextLoader = new DynamicSpringContextLoader(rootApplicationContext);
    for (DeploymentDescriptor dd : application.getResolvedDeployments()) {
        if (dd.isSpringPowered()) {
            springContextLoader.loadSpringContext(dd, application);
            ConfigurableApplicationContext ctx = (ConfigurableApplicationContext) dd.getApplicationContext();
            dd.startDeploy();
            ctx.refresh();
            dd.deployFinish();
        }
    }
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) SpringContextLoader(com.alipay.sofa.isle.loader.SpringContextLoader) DynamicSpringContextLoader(com.alipay.sofa.isle.loader.DynamicSpringContextLoader) GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) FileDeploymentDescriptor(com.alipay.sofa.isle.deployment.impl.FileDeploymentDescriptor) DeploymentDescriptor(com.alipay.sofa.isle.deployment.DeploymentDescriptor) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) DynamicSpringContextLoader(com.alipay.sofa.isle.loader.DynamicSpringContextLoader) SofaModuleProperties(com.alipay.sofa.isle.spring.config.SofaModuleProperties)

Example 2 with DynamicSpringContextLoader

use of com.alipay.sofa.isle.loader.DynamicSpringContextLoader in project sofa-boot by sofastack.

the class BeanHierarchyTest method refreshApplication.

private void refreshApplication(ApplicationRuntimeModel application) throws Exception {
    DefaultListableBeanFactory rootBeanFactory = new DefaultListableBeanFactory();
    ConfigurableApplicationContext rootApplicationContext = new GenericApplicationContext(rootBeanFactory);
    rootApplicationContext.refresh();
    SofaModuleProperties sofaModuleProperties = new SofaModuleProperties();
    sofaModuleProperties.setBeanLoadCost(1);
    rootBeanFactory.registerSingleton("sofaModuleProperties", sofaModuleProperties);
    rootBeanFactory.registerSingleton(SofaBootConstants.PROCESSORS_OF_ROOT_APPLICATION_CONTEXT, new HashMap<>());
    SpringContextLoader springContextLoader = new DynamicSpringContextLoader(rootApplicationContext);
    for (DeploymentDescriptor dd : application.getResolvedDeployments()) {
        if (dd.isSpringPowered()) {
            springContextLoader.loadSpringContext(dd, application);
            ConfigurableApplicationContext ctx = (ConfigurableApplicationContext) dd.getApplicationContext();
            dd.startDeploy();
            ctx.refresh();
            dd.deployFinish();
        }
    }
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) SpringContextLoader(com.alipay.sofa.isle.loader.SpringContextLoader) DynamicSpringContextLoader(com.alipay.sofa.isle.loader.DynamicSpringContextLoader) GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) FileDeploymentDescriptor(com.alipay.sofa.isle.deployment.impl.FileDeploymentDescriptor) DeploymentDescriptor(com.alipay.sofa.isle.deployment.DeploymentDescriptor) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) DynamicSpringContextLoader(com.alipay.sofa.isle.loader.DynamicSpringContextLoader) SofaModuleProperties(com.alipay.sofa.isle.spring.config.SofaModuleProperties)

Aggregations

DeploymentDescriptor (com.alipay.sofa.isle.deployment.DeploymentDescriptor)2 FileDeploymentDescriptor (com.alipay.sofa.isle.deployment.impl.FileDeploymentDescriptor)2 DynamicSpringContextLoader (com.alipay.sofa.isle.loader.DynamicSpringContextLoader)2 SpringContextLoader (com.alipay.sofa.isle.loader.SpringContextLoader)2 SofaModuleProperties (com.alipay.sofa.isle.spring.config.SofaModuleProperties)2 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)2 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)2 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)2