当前位置: 首页>>代码示例>>Java>>正文


Java ConfigurableApplicationContext类代码示例

本文整理汇总了Java中org.springframework.context.ConfigurableApplicationContext的典型用法代码示例。如果您正苦于以下问题:Java ConfigurableApplicationContext类的具体用法?Java ConfigurableApplicationContext怎么用?Java ConfigurableApplicationContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ConfigurableApplicationContext类属于org.springframework.context包,在下文中一共展示了ConfigurableApplicationContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import org.springframework.context.ConfigurableApplicationContext; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public static void main (String[] args){

    ConfigurableApplicationContext ac =
            new ClassPathXmlApplicationContext("/context.xml");
    PollableChannel feedChannel = ac.getBean("feedChannel", PollableChannel.class);

    for (int i = 0; i < 10; i++) {
        Message<SyndEntry> message = (Message<SyndEntry>) feedChannel.receive(1000);
        if (message != null){
            System.out.println("==========="+i+"===========");
            SyndEntry entry = message.getPayload();
            System.out.println(entry.getAuthor());
            System.out.println(entry.getPublishedDate());
            System.out.println(entry.getTitle());
            System.out.println(entry.getUri());
            System.out.println(entry.getLink());
            System.out.println("======================");

        }
    }
    ac.close();


}
 
开发者ID:paulossjunior,项目名称:spring_integration_examples,代码行数:26,代码来源:Application.java

示例2: getApplicationContext

import org.springframework.context.ConfigurableApplicationContext; //导入依赖的package包/类
/**
 * Return the ApplicationContext that this base class manages; may be
 * {@code null}.
 */
public final ConfigurableApplicationContext getApplicationContext() {
	// lazy load, in case setUp() has not yet been called.
	if (this.applicationContext == null) {
		try {
			this.applicationContext = getContext(contextKey());
		}
		catch (Exception e) {
			// log and continue...
			if (this.logger.isDebugEnabled()) {
				this.logger.debug("Caught exception while retrieving the ApplicationContext for test [" +
						getClass().getName() + "." + getName() + "].", e);
			}
		}
	}

	return this.applicationContext;
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:22,代码来源:AbstractSingleSpringContextTests.java

示例3: main

import org.springframework.context.ConfigurableApplicationContext; //导入依赖的package包/类
public static void main(String[] args) {
	try (ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(ScopeConfig.class);) {
		Dictionary singletonDictionary = context.getBean("singletonDictionary", Dictionary.class);
		logger.info("Singleton Scope example starts");
		singletonDictionary.addWord("Give");
		singletonDictionary.addWord("Take");
		int totalWords = singletonDictionary.totalWords();
		logger.info("Need to have two words. Total words are : " + totalWords);
		logger.info(singletonDictionary.toString());
		singletonDictionary = context.getBean("singletonDictionary", Dictionary.class);
		logger.info("Need to have two words. Total words are : " + totalWords);
		logger.info(singletonDictionary.toString());
		logger.info("Singleton Scope example ends");
		
		Dictionary prototypeDictionary = context.getBean("prototypeDictionary", Dictionary.class);
		logger.info("Prototype scope example starts");
		prototypeDictionary.addWord("Give 2");
		prototypeDictionary.addWord("Take 2");
		logger.info("Need to have two words. Total words are: " + prototypeDictionary.totalWords());
		logger.info(prototypeDictionary.toString());
		prototypeDictionary = context.getBean("prototypeDictionary", Dictionary.class);
		logger.info("zero word count. Total words are: " + prototypeDictionary.totalWords());
		logger.info(prototypeDictionary.toString());
	}
}
 
开发者ID:gauravrmazra,项目名称:gauravbytes,代码行数:26,代码来源:App.java

示例4: findWebApplicationContext

import org.springframework.context.ConfigurableApplicationContext; //导入依赖的package包/类
/**
 * Return the {@code WebApplicationContext} passed in at construction time, if available.
 * Otherwise, attempt to retrieve a {@code WebApplicationContext} from the
 * {@code ServletContext} attribute with the {@linkplain #setContextAttribute
 * configured name} if set. Otherwise look up a {@code WebApplicationContext} under
 * the well-known "root" application context attribute. The
 * {@code WebApplicationContext} must have already been loaded and stored in the
 * {@code ServletContext} before this filter gets initialized (or invoked).
 * <p>Subclasses may override this method to provide a different
 * {@code WebApplicationContext} retrieval strategy.
 * @return the {@code WebApplicationContext} for this proxy, or {@code null} if not found
 * @see #DelegatingFilterProxy(String, WebApplicationContext)
 * @see #getContextAttribute()
 * @see WebApplicationContextUtils#getWebApplicationContext(javax.servlet.ServletContext)
 * @see WebApplicationContext#ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE
 */
protected WebApplicationContext findWebApplicationContext() {
	if (this.webApplicationContext != null) {
		// the user has injected a context at construction time -> use it
		if (this.webApplicationContext instanceof ConfigurableApplicationContext) {
			if (!((ConfigurableApplicationContext)this.webApplicationContext).isActive()) {
				// the context has not yet been refreshed -> do so before returning it
				((ConfigurableApplicationContext)this.webApplicationContext).refresh();
			}
		}
		return this.webApplicationContext;
	}
	String attrName = getContextAttribute();
	if (attrName != null) {
		return WebApplicationContextUtils.getWebApplicationContext(getServletContext(), attrName);
	}
	else {
		return WebApplicationContextUtils.getWebApplicationContext(getServletContext());
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:36,代码来源:DelegatingFilterProxy.java

示例5: afterPropertiesSet

import org.springframework.context.ConfigurableApplicationContext; //导入依赖的package包/类
@Override
public void afterPropertiesSet() throws Exception {
    if (this.propertySources == null) {
        this.propertySources = deducePropertySources();
    }

    if (this.conversionService == null) {
        this.conversionService = getOptionalBean(
                ConfigurableApplicationContext.CONVERSION_SERVICE_BEAN_NAME,
                ConfigurableConversionService.class);
    }

    // If no explicit conversion service is provided we add one so that (at least)
    // comma-separated arrays of convertibles can be bound automatically
    if (this.conversionService == null) {
        this.conversionService = getDefaultConversionService();
    }

    this.propertyResolver = new PropertySourcesPropertyResolver(this.propertySources);
    this.propertyResolver.setConversionService(this.conversionService);
}
 
开发者ID:zouzhirong,项目名称:configx,代码行数:22,代码来源:ConfigPropertyResolver.java

示例6: postProcessBeforeInitialization

import org.springframework.context.ConfigurableApplicationContext; //导入依赖的package包/类
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
	if (bean instanceof LoadTimeWeaverAware) {
		LoadTimeWeaver ltw = this.loadTimeWeaver;
		if (ltw == null) {
			Assert.state(this.beanFactory != null,
					"BeanFactory required if no LoadTimeWeaver explicitly specified");
			ltw = this.beanFactory.getBean(
					ConfigurableApplicationContext.LOAD_TIME_WEAVER_BEAN_NAME, LoadTimeWeaver.class);
		}
		((LoadTimeWeaverAware) bean).setLoadTimeWeaver(ltw);
	}
	return bean;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:15,代码来源:LoadTimeWeaverAwareProcessor.java

示例7: main

import org.springframework.context.ConfigurableApplicationContext; //导入依赖的package包/类
public static void main(String[] args) {
    SpringApplicationBuilder builder = new SpringApplicationBuilder(Launcher.class);
    Set<ApplicationListener<?>> listeners = builder.application().getListeners();
    for (Iterator<ApplicationListener<?>> it = listeners.iterator(); it.hasNext();) {
        ApplicationListener<?> listener = it.next();
        if (listener instanceof LoggingApplicationListener) {
            it.remove();
        }
    }
    builder.application().setListeners(listeners);
    ConfigurableApplicationContext context = builder.run(args);
    LOGGER.info("collector metrics start successfully");

    KafkaConsumer kafkaConsumer = (KafkaConsumer<byte[], String>) context.getBean("kafkaConsumer");
    Task task = (Task) context.getBean("metricsTask");

    // 优雅停止项目
    Runtime.getRuntime().addShutdownHook(new ShutdownHookRunner(kafkaConsumer, task));
    task.doTask();
}
 
开发者ID:JThink,项目名称:SkyEye,代码行数:21,代码来源:Launcher.java

示例8: main

import org.springframework.context.ConfigurableApplicationContext; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
    ConfigurableApplicationContext context = SpringApplication.run(AemOrchestrator.class, args);
    
    //Need to wait for Author ELB is be in a healthy state before reading messages from the SQS queue
    ResourceReadyChecker resourceReadyChecker = context.getBean(ResourceReadyChecker.class);
    
    boolean isStartupOk = false;
    
    if(resourceReadyChecker.isResourcesReady()) {
        OrchestratorMessageListener messageReceiver = context.getBean(OrchestratorMessageListener.class);
        
        try {
            messageReceiver.start();
            isStartupOk = true;
        } catch (Exception e) {
            logger.error("Failed to start message receiver", e);
        }
    }
    
    if(isStartupOk) {
        logger.info("AEM Orchestrator started");
    } else {
        logger.info("Failed to start AEM Orchestrator");
        context.close(); //Exit the application
    }
}
 
开发者ID:shinesolutions,项目名称:aem-orchestrator,代码行数:27,代码来源:AemOrchestrator.java

示例9: HandlerMethodService

import org.springframework.context.ConfigurableApplicationContext; //导入依赖的package包/类
public HandlerMethodService(ConversionService conversionService,
		List<HandlerMethodArgumentResolver> customArgumentResolvers,
		ObjectMapper objectMapper, ApplicationContext applicationContext) {
	this.conversionService = conversionService;
	this.parameterNameDiscoverer = new DefaultParameterNameDiscoverer();

	this.argumentResolvers = new HandlerMethodArgumentResolverComposite();

	ConfigurableBeanFactory beanFactory = ClassUtils.isAssignableValue(
			ConfigurableApplicationContext.class, applicationContext)
					? ((ConfigurableApplicationContext) applicationContext)
							.getBeanFactory()
					: null;

	this.argumentResolvers.addResolver(
			new HeaderMethodArgumentResolver(this.conversionService, beanFactory));
	this.argumentResolvers.addResolver(new HeadersMethodArgumentResolver());
	this.argumentResolvers.addResolver(new WampMessageMethodArgumentResolver());
	this.argumentResolvers.addResolver(new PrincipalMethodArgumentResolver());
	this.argumentResolvers.addResolver(new WampSessionIdMethodArgumentResolver());
	this.argumentResolvers.addResolvers(customArgumentResolvers);

	this.objectMapper = objectMapper;
}
 
开发者ID:ralscha,项目名称:wamp2spring,代码行数:25,代码来源:HandlerMethodService.java

示例10: run

import org.springframework.context.ConfigurableApplicationContext; //导入依赖的package包/类
public void run(Class clazz, String[] args) {
        SpringApplication springApplication = new SpringApplication(clazz);
//        springApplication.addListeners(new ApplicationPidFileWriter("application.pid"));
        ConfigurableApplicationContext ctx = springApplication.run(args);
        Environment env = ctx.getEnvironment();
        if (env.acceptsProfiles(ProfileConstant.RT_SCRIPT)) {
            if (args.length > 0) {
                String shellClass = args[0];
                ScriptInterface script = (ScriptInterface) ctx.getBean(shellClass);
                if (null != script) {
                    try {
                        if (args.length > 1) {
                            script.run(Arrays.copyOfRange(args, 1, args.length));
                        } else {
                            script.run(new String[]{});
                        }
                    } catch (Exception e) {
                        scriptLogger.error("error occur", e);
                    }
                }
            }
        }
    }
 
开发者ID:superkoh,项目名称:k-framework,代码行数:24,代码来源:KApplication.java

示例11: main

import org.springframework.context.ConfigurableApplicationContext; //导入依赖的package包/类
public static void main(String[] args) throws InterruptedException {
    log.info("Initializing channel node");
    ConfigurableApplicationContext context = SpringApplication.run(ChannelNodeApplication.class, args);
    log.info("Starting API interfaces");
    context.start();
    NodeServer nodeServer = context.getBean(NodeServer.class);
    log.info("Channel node started");
    nodeServer.awaitTermination();
}
 
开发者ID:papyrusglobal,项目名称:state-channels,代码行数:10,代码来源:ChannelNodeApplication.java

示例12: main

import org.springframework.context.ConfigurableApplicationContext; //导入依赖的package包/类
public static void main(String[] args) {
    SpringApplicationBuilder builder = new SpringApplicationBuilder(Launcher.class);
    Set<ApplicationListener<?>> listeners = builder.application().getListeners();
    for (Iterator<ApplicationListener<?>> it = listeners.iterator(); it.hasNext();) {
        ApplicationListener<?> listener = it.next();
        if (listener instanceof LoggingApplicationListener) {
            it.remove();
        }
    }
    builder.application().setListeners(listeners);
    ConfigurableApplicationContext context = builder.run(args);
    LOGGER.info("collector indexer start successfully");

    KafkaConsumer kafkaConsumer = (KafkaConsumer<byte[], String>) context.getBean("kafkaConsumer");
    Task task = (Task) context.getBean("indexerTask");

    // 优雅停止项目
    Runtime.getRuntime().addShutdownHook(new ShutdownHookRunner(kafkaConsumer, task));
    task.doTask();
}
 
开发者ID:JThink,项目名称:SkyEye,代码行数:21,代码来源:Launcher.java

示例13: customizeContext

import org.springframework.context.ConfigurableApplicationContext; //导入依赖的package包/类
@Override
public void customizeContext(ConfigurableApplicationContext context, MergedContextConfiguration mergedConfig) {
    Class<?> testClass = mergedConfig.getTestClass();
    FlywayTest flywayAnnotation = AnnotatedElementUtils.findMergedAnnotation(testClass, FlywayTest.class);

    BeanDefinitionRegistry registry = getBeanDefinitionRegistry(context);
    RootBeanDefinition registrarDefinition = new RootBeanDefinition();

    registrarDefinition.setBeanClass(PreloadableEmbeddedPostgresRegistrar.class);
    registrarDefinition.getConstructorArgumentValues()
            .addIndexedArgumentValue(0, databaseAnnotation);
    registrarDefinition.getConstructorArgumentValues()
            .addIndexedArgumentValue(1, flywayAnnotation);

    registry.registerBeanDefinition("preloadableEmbeddedPostgresRegistrar", registrarDefinition);
}
 
开发者ID:zonkyio,项目名称:embedded-database-spring-test,代码行数:17,代码来源:EmbeddedPostgresContextCustomizerFactory.java

示例14: main

import org.springframework.context.ConfigurableApplicationContext; //导入依赖的package包/类
public static void main(String[] args) {
    final SpringApplication app = new SpringApplication(Application.class);
    // save the pid into a file...
    app.addListeners(new ApplicationPidFileWriter("smarti.pid"));

    final ConfigurableApplicationContext context = app.run(args);
    final ConfigurableEnvironment env = context.getEnvironment();

    try {
        //http://localhost:8080/admin/index.html
        final URI uri = new URI(
                (env.getProperty("server.ssl.enabled", Boolean.class, false) ? "https" : "http"),
                null,
                (env.getProperty("server.address", "localhost")),
                (env.getProperty("server.port", Integer.class, 8080)),
                (env.getProperty("server.context-path", "/")).replaceAll("//+", "/"),
                null, null);

        log.info("{} started: {}",
                env.getProperty("server.display-name", context.getDisplayName()),
                uri);
    } catch (URISyntaxException e) {
        log.warn("Could not build launch-url: {}", e.getMessage());
    }
}
 
开发者ID:redlink-gmbh,项目名称:smarti,代码行数:26,代码来源:Application.java

示例15: postProcessBeanDefinitionRegistry

import org.springframework.context.ConfigurableApplicationContext; //导入依赖的package包/类
@Override
public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException {
    /**
     * 注册通用Dao
     */
    registerBaseCommonDao(registry);
    /**
     * 注册代理类
     */
    registerProxyHandler(registry);
    /**
     * 加载其他层接口
     */
    ClassPathMapperScanner scanner = new ClassPathMapperScanner(registry, annotation);
    scanner.scan(StringUtils.tokenizeToStringArray(this.basePackage, ConfigurableApplicationContext.CONFIG_LOCATION_DELIMITERS));
}
 
开发者ID:lftao,项目名称:jkami,代码行数:17,代码来源:MapperScannerConfigurer.java


注:本文中的org.springframework.context.ConfigurableApplicationContext类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。