Java Code Examples for org.springframework.context.annotation.AnnotationConfigApplicationContext#setClassLoader()

The following examples show how to use org.springframework.context.annotation.AnnotationConfigApplicationContext#setClassLoader() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: sbp   File: SpringBootstrap.java    License: Apache License 2.0 6 votes vote down vote up
@Override
    public ConfigurableApplicationContext createApplicationContext() {
        setWebApplicationType(WebApplicationType.NONE);
        AnnotationConfigApplicationContext applicationContext =
                (AnnotationConfigApplicationContext) super.createApplicationContext();
//        applicationContext.setParent(mainApplicationContext);
        hackBeanFactory(applicationContext);
        applicationContext.setClassLoader(pluginClassLoader);

        applicationContext.getBeanFactory().registerSingleton(BEAN_PLUGIN, plugin);
        applicationContext.getBeanFactory().autowireBean(plugin);

        if (!CollectionUtils.isEmpty(sharedBeanNames)) {
            for (String beanName : sharedBeanNames) {
                registerBeanFromMainContext(applicationContext, beanName);
            }
        }

        return applicationContext;
    }
 
Example 2
AbstractApplicationContext createApplicationContext(Domain domain) {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
    context.setParent(gatewayApplicationContext);
    context.setClassLoader(new ReactorHandlerClassLoader(gatewayApplicationContext.getClassLoader()));
    context.setEnvironment((ConfigurableEnvironment) gatewayApplicationContext.getEnvironment());

    PropertySourcesPlaceholderConfigurer configurer = new PropertySourcesPlaceholderConfigurer();
    configurer.setIgnoreUnresolvablePlaceholders(true);
    configurer.setEnvironment(gatewayApplicationContext.getEnvironment());
    context.addBeanFactoryPostProcessor(configurer);

    context.getBeanFactory().registerSingleton("domain", domain);
    context.register(HandlerConfiguration.class);
    context.setId("context-domain-" + domain.getId());
    context.refresh();

    return context;
}
 
Example 3
AbstractApplicationContext createApplicationContext(Api api) {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
    context.setParent(gatewayApplicationContext);
    context.setClassLoader(new ReactorHandlerClassLoader(gatewayApplicationContext.getClassLoader()));
    context.setEnvironment((ConfigurableEnvironment) gatewayApplicationContext.getEnvironment());

    PropertySourcesPlaceholderConfigurer configurer = new PropertySourcesPlaceholderConfigurer();
    configurer.setIgnoreUnresolvablePlaceholders(true);
    configurer.setEnvironment(gatewayApplicationContext.getEnvironment());
    context.addBeanFactoryPostProcessor(configurer);

    context.getBeanFactory().registerSingleton("api", api);
    context.register(ApiHandlerConfiguration.class);
    context.setId("context-api-" + api.getId());
    context.refresh();

    return context;
}
 
Example 4
@Override
protected ApplicationContext createApplicationContext() {
    AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
    applicationContext.setClassLoader(getWrapper().getPluginClassLoader());
    applicationContext.register(ApplicationConfiguration.class);
    applicationContext.refresh();
    return applicationContext;
}
 
Example 5
@Override
public ProtocolProvider create(String type, ApplicationContext parentContext) {
    logger.debug("Looking for an protocol provider for [{}]", type);
    Protocol protocol = protocols.get(type);
    if (protocol != null) {
        try {
            ProtocolProvider protocolProvider = createInstance(protocol.protocolProvider());
            Plugin plugin = protocolPlugins.get(protocol);

            AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
            context.setParent(parentContext);
            context.setClassLoader(pluginClassLoaderFactory.getOrCreateClassLoader(plugin));
            context.setEnvironment((ConfigurableEnvironment) parentContext.getEnvironment());

            PropertySourcesPlaceholderConfigurer configurer = new PropertySourcesPlaceholderConfigurer();
            configurer.setIgnoreUnresolvablePlaceholders(true);
            configurer.setEnvironment(parentContext.getEnvironment());
            context.addBeanFactoryPostProcessor(configurer);

            context.register(protocol.configuration());
            context.registerBeanDefinition(plugin.clazz(), BeanDefinitionBuilder.rootBeanDefinition(plugin.clazz()).getBeanDefinition());
            context.refresh();

            context.getAutowireCapableBeanFactory().autowireBean(protocolProvider);

            if (protocolProvider instanceof InitializingBean) {
                ((InitializingBean) protocolProvider).afterPropertiesSet();
            }
            return protocolProvider;
        } catch (Exception ex) {
            logger.error("An unexpected error occurs while loading protocol", ex);
            return null;
        }
    } else {
        logger.error("No protocol provider is registered for type {}", type);
        throw new IllegalStateException("No protocol provider is registered for type " + type);
    }
}
 
Example 6
Source Project: pf4j-spring   File: HelloPlugin.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected ApplicationContext createApplicationContext() {
    AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
    applicationContext.setClassLoader(getWrapper().getPluginClassLoader());
    applicationContext.register(SpringConfiguration.class);
    applicationContext.refresh();

    return applicationContext;
}