當前位置: 首頁>>代碼示例>>Java>>正文


Java AbstractApplicationContext類代碼示例

本文整理匯總了Java中org.springframework.context.support.AbstractApplicationContext的典型用法代碼示例。如果您正苦於以下問題:Java AbstractApplicationContext類的具體用法?Java AbstractApplicationContext怎麽用?Java AbstractApplicationContext使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


AbstractApplicationContext類屬於org.springframework.context.support包,在下文中一共展示了AbstractApplicationContext類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: init

import org.springframework.context.support.AbstractApplicationContext; //導入依賴的package包/類
public void init() {
    //啟動並設置Spring
    AbstractApplicationContext ctx = new AnnotationConfigApplicationContext(SpringConfig.class);
    ctx.registerShutdownHook();
    NContext.setApplicationContext(ctx);

    //初始化房間管理器
    HomeManager homeManager = HomeManager.getInstance();
    homeManager.init();

    //初始化用戶管理器
    PlayerManager playerManager = PlayerManager.getInstance();
    playerManager.init();

    //初始化Gateway
    ClientManager clientManager = ClientManager.getInstance();
    clientManager.init();

    //啟動異步處理器
    AsyncProcessor asyncProcessor = AsyncProcessor.getInstance();
    asyncProcessor.start();

    //啟動滴答服務
    TickerService tickerService = TickerService.getInstance();
    tickerService.start();
}
 
開發者ID:ninelook,項目名稱:wecard-server,代碼行數:27,代碼來源:NServer.java

示例2: configureMessageSource

import org.springframework.context.support.AbstractApplicationContext; //導入依賴的package包/類
/**
 * 配置基於配置的MessageSource
 */
private void configureMessageSource() {
    // MessageSource bean name
    String messageSourceBeanName = AbstractApplicationContext.MESSAGE_SOURCE_BEAN_NAME;

    // Config MessageSource bean name
    String configMessageSourceBeanName = CONFIG_MESSAGE_SOURCE_BEAN_NAME;

    // 基於配置服務的MessageSource
    ConfigMessageSource configMessageSource = beanFactory.getBean(configMessageSourceBeanName, ConfigMessageSource.class);

    // 如果已經存在MessageSource bean,則將ConfigMessageSource設置為messageSource的parent,將messageSource原來的parent設置為ConfigMessageSource的parent
    if (beanFactory.containsLocalBean(messageSourceBeanName)) {
        MessageSource messageSource = beanFactory.getBean(messageSourceBeanName, MessageSource.class);
        if (messageSource instanceof HierarchicalMessageSource) {
            HierarchicalMessageSource hms = (HierarchicalMessageSource) messageSource;
            MessageSource pms = hms.getParentMessageSource();

            hms.setParentMessageSource(configMessageSource);
            configMessageSource.setParentMessageSource(pms);
        }
    } else {
        beanFactory.registerSingleton(messageSourceBeanName, configMessageSource);
    }
}
 
開發者ID:zouzhirong,項目名稱:configx,代碼行數:28,代碼來源:ConfigMessageSourceConfigurer.java

示例3: testAppContextClassHierarchy

import org.springframework.context.support.AbstractApplicationContext; //導入依賴的package包/類
public void testAppContextClassHierarchy() {
	Class<?>[] clazz =
			ClassUtils.getClassHierarchy(OsgiBundleXmlApplicationContext.class, ClassUtils.ClassSet.ALL_CLASSES);

       //Closeable.class,
	Class<?>[] expected =
			new Class<?>[] { OsgiBundleXmlApplicationContext.class,
					AbstractDelegatedExecutionApplicationContext.class, AbstractOsgiBundleApplicationContext.class,
					AbstractRefreshableApplicationContext.class, AbstractApplicationContext.class,
					DefaultResourceLoader.class, ResourceLoader.class,
					AutoCloseable.class,
					DelegatedExecutionOsgiBundleApplicationContext.class,
					ConfigurableOsgiBundleApplicationContext.class, ConfigurableApplicationContext.class,
					ApplicationContext.class, Lifecycle.class, Closeable.class, EnvironmentCapable.class, ListableBeanFactory.class,
					HierarchicalBeanFactory.class, ApplicationEventPublisher.class, ResourcePatternResolver.class,
					MessageSource.class, BeanFactory.class, DisposableBean.class };

	assertTrue(compareArrays(expected, clazz));
}
 
開發者ID:eclipse,項目名稱:gemini.blueprint,代碼行數:20,代碼來源:ClassUtilsTest.java

示例4: main

import org.springframework.context.support.AbstractApplicationContext; //導入依賴的package包/類
public static void main (String [] args)
{
	@SuppressWarnings({ "resource"})
	AbstractApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class);
	
	PumpEngine engine = (PumpEngine)context.getBean(PumpEngine.class);
	engine.setArgs(args);
	try {
		engine.startPump();
	} catch (Exception e) {			
		logger.error("Exception Occured while doing buy/sell transaction", e);			
	}		
	
	System.out.println("\n\n\nHope you will make a profit in this pump ;)");
	System.out.println("if you could make a proit using this app please conside doing some donation with 1$ or 2$ to BTC address 1PfnwEdmU3Ki9htakiv4tciPXzo49RRkai \nit will help us doing more features in the future");
}
 
開發者ID:rgf2004,項目名稱:easypump,代碼行數:17,代碼來源:Main.java

示例5: getApplicationContext

import org.springframework.context.support.AbstractApplicationContext; //導入依賴的package包/類
/**
 * Provides a static, single instance of the application context.  This method can be
 * called repeatedly.
 * <p/>
 * If the configuration requested differs from one used previously, then the previously-created
 * context is shut down.
 * 
 * @return Returns an application context for the given configuration
 */
public synchronized static ConfigurableApplicationContext getApplicationContext(ServletContext servletContext, String[] configLocations)
{
	AbstractApplicationContext ctx = (AbstractApplicationContext)BaseApplicationContextHelper.getApplicationContext(configLocations);
	
	CmisServiceFactory factory = (CmisServiceFactory)ctx.getBean("CMISServiceFactory");
	
	DefaultListableBeanFactory dlbf = new DefaultListableBeanFactory(ctx.getBeanFactory());
	GenericWebApplicationContext gwac = new GenericWebApplicationContext(dlbf);
	servletContext.setAttribute(GenericWebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, gwac);
       servletContext.setAttribute(CmisRepositoryContextListener.SERVICES_FACTORY, factory);
	gwac.setServletContext(servletContext);
	gwac.refresh();

	return gwac;
}
 
開發者ID:Alfresco,項目名稱:alfresco-data-model,代碼行數:25,代碼來源:WebApplicationContextLoader.java

示例6: load

import org.springframework.context.support.AbstractApplicationContext; //導入依賴的package包/類
static public AbstractApplicationContext load() {
    AbstractApplicationContext context;

    try {
        context = AnnotationConfigApplicationContext.class.newInstance();
    } catch (InstantiationException | IllegalAccessException e) {
        throw new RuntimeException(e);
    }

    AnnotationConfigRegistry registry = (AnnotationConfigRegistry) context;

    registry.register(BaseConfiguration.class);
    registry.register(GraphQLJavaToolsAutoConfiguration.class);

    context.refresh();

    return context;
}
 
開發者ID:donbeave,項目名稱:graphql-java-datetime,代碼行數:19,代碼來源:ContextHelper.java

示例7: listenersInApplicationContextWithNestedChild

import org.springframework.context.support.AbstractApplicationContext; //導入依賴的package包/類
@Test
public void listenersInApplicationContextWithNestedChild() {
	StaticApplicationContext context = new StaticApplicationContext();
	RootBeanDefinition nestedChild = new RootBeanDefinition(StaticApplicationContext.class);
	nestedChild.getPropertyValues().add("parent", context);
	nestedChild.setInitMethodName("refresh");
	context.registerBeanDefinition("nestedChild", nestedChild);
	RootBeanDefinition listener1Def = new RootBeanDefinition(MyOrderedListener1.class);
	listener1Def.setDependsOn("nestedChild");
	context.registerBeanDefinition("listener1", listener1Def);
	context.refresh();

	MyOrderedListener1 listener1 = context.getBean("listener1", MyOrderedListener1.class);
	MyEvent event1 = new MyEvent(context);
	context.publishEvent(event1);
	assertTrue(listener1.seenEvents.contains(event1));

	SimpleApplicationEventMulticaster multicaster = context.getBean(
			AbstractApplicationContext.APPLICATION_EVENT_MULTICASTER_BEAN_NAME,
			SimpleApplicationEventMulticaster.class);
	assertFalse(multicaster.getApplicationListeners().isEmpty());

	context.close();
	assertTrue(multicaster.getApplicationListeners().isEmpty());
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:26,代碼來源:ApplicationContextEventTests.java

示例8: getEventFiringWebDriver

import org.springframework.context.support.AbstractApplicationContext; //導入依賴的package包/類
/**
 * This method makes an event firing instance of {@link org.openqa.selenium.WebDriver}
 *
 * @param driver an original instance of {@link org.openqa.selenium.WebDriver} that is
 *               supposed to be listenable
 * @param listeners is a collection of {@link Listener} that
 *                  is supposed to be used for the event firing
 * @param <T> T
 * @return an instance of {@link org.openqa.selenium.WebDriver} that fires events
 */
@SuppressWarnings("unchecked")
public static <T extends WebDriver> T getEventFiringWebDriver(T driver, Collection<Listener> listeners) {
    List<Listener> listenerList = new ArrayList<>();
    Iterator<Listener> providers = ServiceLoader.load(
        Listener.class).iterator();

    while (providers.hasNext()) {
        listenerList.add(providers.next());
    }

    listenerList.addAll(listeners);

    AbstractApplicationContext context = new AnnotationConfigApplicationContext(
        DefaultBeanConfiguration.class);
    return (T) context.getBean(
        DefaultBeanConfiguration.WEB_DRIVER_BEAN, driver, listenerList, context);
}
 
開發者ID:JoeUtt,項目名稱:menggeqa,代碼行數:28,代碼來源:EventFiringWebDriverFactory.java

示例9: doCreateApplicationContext

import org.springframework.context.support.AbstractApplicationContext; //導入依賴的package包/類
private AbstractApplicationContext doCreateApplicationContext() {
    AbstractApplicationContext context = createApplicationContext();
    assertNotNull("Should have created a valid Spring application context", context);

    String[] profiles = activeProfiles();
    if (profiles != null && profiles.length > 0) {
        // the context must not be active
        if (context.isActive()) {
            throw new IllegalStateException("Cannot active profiles: " + Arrays.asList(profiles) + " on active Spring application context: " + context
                + ". The code in your createApplicationContext() method should be adjusted to create the application context with refresh = false as parameter");
        }
        log.info("Spring activating profiles: {}", Arrays.asList(profiles));
        context.getEnvironment().setActiveProfiles(profiles);
    }

    // ensure the context has been refreshed at least once
    if (!context.isActive()) {
        context.refresh();
    }

    return context;
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:23,代碼來源:CamelSpringTestSupport.java

示例10: refresh

import org.springframework.context.support.AbstractApplicationContext; //導入依賴的package包/類
/**
 * Refreshes the {@link SpringContext}.
 */
public static void refresh()
{
	try
	{
		logger.info("Reloading the App context: " + SpringContext.getConfigFileName());
		if (ObjectUtils.isInstanceOf(appContext, AbstractApplicationContext.class))
		{
			((AbstractApplicationContext) appContext).refresh();
		}
		logger.info("Successfully Reloaded the App context: " + SpringContext.getConfigFileName());
		lastLoaded = System.currentTimeMillis();
	}
	catch (Exception e)
	{
		e.printStackTrace(System.err);
		logger.error("Context file is not reloaded, got error while reloading the config file.", e);
	}
}
 
開發者ID:varra4u,項目名稱:utils4j,代碼行數:22,代碼來源:SpringContextProvider.java

示例11: main

import org.springframework.context.support.AbstractApplicationContext; //導入依賴的package包/類
public static void main(final String[] args) throws Exception {
    System.out.println("Notice this client requires that the CamelServer is already running!");

    AbstractApplicationContext context = new ClassPathXmlApplicationContext("camel-client.xml");

    // get the camel template for Spring template style sending of messages (= producer)
    ProducerTemplate camelTemplate = context.getBean("camelTemplate", ProducerTemplate.class);

    System.out.println("Invoking the multiply with 22");
    // as opposed to the CamelClientRemoting example we need to define the service URI in this java code
    int response = (Integer)camelTemplate.sendBody("jms:queue:numbers", ExchangePattern.InOut, 22);
    System.out.println("... the result is: " + response);

    // we're done so let's properly close the application context
    IOHelper.close(context);
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:17,代碼來源:CamelClient.java

示例12: main

import org.springframework.context.support.AbstractApplicationContext; //導入依賴的package包/類
public static void main(final String[] args) throws Exception {
    AbstractApplicationContext context = new ClassPathXmlApplicationContext("camel-file-client.xml");

    // get the camel template for Spring template style sending of messages (= producer)
    final ProducerTemplate producer = context.getBean("camelTemplate", ProducerTemplate.class);

    // now send a lot of messages
    System.out.println("Writing files ...");

    for (int i = 0; i < SIZE; i++) {
        producer.sendBodyAndHeader("file:target//inbox", "File " + i, Exchange.FILE_NAME, i + ".txt");
    }

    System.out.println("... Wrote " + SIZE + " files");

    // we're done so let's properly close the application context
    IOHelper.close(context);
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:19,代碼來源:CamelFileClient.java

示例13: main

import org.springframework.context.support.AbstractApplicationContext; //導入依賴的package包/類
public static void main(String[] args) throws Exception {
  	final String pckName = POIVisualizer.class.getPackage().getName();
  	try (AbstractApplicationContext ctx = new AnnotationConfigApplicationContext(pckName)) {
  		POIVisualizer visualizer = ctx.getBean(POIVisualizer.class);
  		visualizer.start();
  	}

System.out.println("Exiting");
  }
 
開發者ID:kiwiwings,項目名稱:poi-visualizer,代碼行數:10,代碼來源:POIVisualizer.java

示例14: testCseApplicationListenerThrowException

import org.springframework.context.support.AbstractApplicationContext; //導入依賴的package包/類
@Test
public void testCseApplicationListenerThrowException(@Injectable ContextRefreshedEvent event,
    @Injectable AbstractApplicationContext context,
    @Injectable BootListener listener,
    @Injectable ProducerProviderManager producerProviderManager,
    @Mocked RegistryUtils ru) {
  Map<String, BootListener> listeners = new HashMap<>();
  listeners.put("test", listener);

  CseApplicationListener cal = new CseApplicationListener();
  cal.setApplicationContext(context);
  ReflectUtils.setField(cal, "producerProviderManager", producerProviderManager);
  cal.onApplicationEvent(event);
}
 
開發者ID:apache,項目名稱:incubator-servicecomb-java-chassis,代碼行數:15,代碼來源:TestCseApplicationListener.java

示例15: testCseApplicationListenerParentNotnull

import org.springframework.context.support.AbstractApplicationContext; //導入依賴的package包/類
@Test
public void testCseApplicationListenerParentNotnull(@Injectable ContextRefreshedEvent event,
    @Injectable AbstractApplicationContext context,
    @Injectable AbstractApplicationContext pContext,
    @Mocked RegistryUtils ru) {

  CseApplicationListener cal = new CseApplicationListener();
  cal.setApplicationContext(context);
  cal.onApplicationEvent(event);
}
 
開發者ID:apache,項目名稱:incubator-servicecomb-java-chassis,代碼行數:11,代碼來源:TestCseApplicationListener.java


注:本文中的org.springframework.context.support.AbstractApplicationContext類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。