use of com.alipay.sofa.isle.spring.context.SofaModuleApplicationContext in project sofa-boot by alipay.
the class DynamicSpringContextLoader method loadSpringContext.
@Override
public void loadSpringContext(DeploymentDescriptor deployment, ApplicationRuntimeModel application) throws Exception {
SofaModuleProperties sofaModuleProperties = rootApplicationContext.getBean(SofaModuleProperties.class);
BeanLoadCostBeanFactory beanFactory = new BeanLoadCostBeanFactory(sofaModuleProperties.getBeanLoadCost(), deployment.getModuleName());
beanFactory.setAutowireCandidateResolver(new QualifierAnnotationAutowireCandidateResolver());
GenericApplicationContext ctx = sofaModuleProperties.isPublishEventToParent() ? new GenericApplicationContext(beanFactory) : new SofaModuleApplicationContext(beanFactory);
ctx.setId(deployment.getModuleName());
String activeProfiles = sofaModuleProperties.getActiveProfiles();
if (StringUtils.hasText(activeProfiles)) {
String[] profiles = activeProfiles.split(SofaBootConstants.PROFILE_SEPARATOR);
ctx.getEnvironment().setActiveProfiles(profiles);
}
setUpParentSpringContext(ctx, deployment, application);
final ClassLoader moduleClassLoader = deployment.getClassLoader();
ctx.setClassLoader(moduleClassLoader);
CachedIntrospectionResults.acceptClassLoader(moduleClassLoader);
// set allowBeanDefinitionOverriding
ctx.setAllowBeanDefinitionOverriding(sofaModuleProperties.isAllowBeanDefinitionOverriding());
ctx.getBeanFactory().setBeanClassLoader(moduleClassLoader);
ctx.getBeanFactory().addPropertyEditorRegistrar(new PropertyEditorRegistrar() {
public void registerCustomEditors(PropertyEditorRegistry registry) {
registry.registerCustomEditor(Class.class, new ClassEditor(moduleClassLoader));
registry.registerCustomEditor(Class[].class, new ClassArrayEditor(moduleClassLoader));
}
});
deployment.setApplicationContext(ctx);
XmlBeanDefinitionReader beanDefinitionReader = new XmlBeanDefinitionReader(ctx);
beanDefinitionReader.setValidating(true);
beanDefinitionReader.setNamespaceAware(true);
beanDefinitionReader.setBeanClassLoader(deployment.getApplicationContext().getClassLoader());
beanDefinitionReader.setResourceLoader(ctx);
loadBeanDefinitions(deployment, beanDefinitionReader);
addPostProcessors(beanFactory);
}
use of com.alipay.sofa.isle.spring.context.SofaModuleApplicationContext in project sofa-boot by sofastack.
the class DynamicSpringContextLoader method loadSpringContext.
@Override
public void loadSpringContext(DeploymentDescriptor deployment, ApplicationRuntimeModel application) throws Exception {
SofaModuleProperties sofaModuleProperties = rootApplicationContext.getBean(SofaModuleProperties.class);
BeanLoadCostBeanFactory beanFactory = new BeanLoadCostBeanFactory(sofaModuleProperties.getBeanLoadCost(), deployment.getModuleName());
beanFactory.setAutowireCandidateResolver(new QualifierAnnotationAutowireCandidateResolver());
GenericApplicationContext ctx = sofaModuleProperties.isPublishEventToParent() ? new GenericApplicationContext(beanFactory) : new SofaModuleApplicationContext(beanFactory);
ctx.setId(deployment.getModuleName());
String activeProfiles = sofaModuleProperties.getActiveProfiles();
if (StringUtils.hasText(activeProfiles)) {
String[] profiles = activeProfiles.split(SofaBootConstants.PROFILE_SEPARATOR);
ctx.getEnvironment().setActiveProfiles(profiles);
}
setUpParentSpringContext(ctx, deployment, application);
final ClassLoader moduleClassLoader = deployment.getClassLoader();
ctx.setClassLoader(moduleClassLoader);
CachedIntrospectionResults.acceptClassLoader(moduleClassLoader);
// set allowBeanDefinitionOverriding
ctx.setAllowBeanDefinitionOverriding(sofaModuleProperties.isAllowBeanDefinitionOverriding());
ctx.getBeanFactory().setBeanClassLoader(moduleClassLoader);
ctx.getBeanFactory().addPropertyEditorRegistrar(new PropertyEditorRegistrar() {
public void registerCustomEditors(PropertyEditorRegistry registry) {
registry.registerCustomEditor(Class.class, new ClassEditor(moduleClassLoader));
registry.registerCustomEditor(Class[].class, new ClassArrayEditor(moduleClassLoader));
}
});
deployment.setApplicationContext(ctx);
XmlBeanDefinitionReader beanDefinitionReader = new XmlBeanDefinitionReader(ctx);
beanDefinitionReader.setValidating(true);
beanDefinitionReader.setNamespaceAware(true);
beanDefinitionReader.setBeanClassLoader(deployment.getApplicationContext().getClassLoader());
beanDefinitionReader.setResourceLoader(ctx);
loadBeanDefinitions(deployment, beanDefinitionReader);
addPostProcessors(beanFactory);
}
Aggregations