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


Java AnnotationConfigApplicationContext類代碼示例

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


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

示例1: provideCollectorComponent_canSetStorageContainerName

import org.springframework.context.annotation.AnnotationConfigApplicationContext; //導入依賴的package包/類
@Test
public void provideCollectorComponent_canSetStorageContainerName() {

    String storageContainerName = "pashmak";

    context = new AnnotationConfigApplicationContext();
    addEnvironment(context, "zipkin.collector.eventhub.storageConnectionString:" + dummyEventHubConnectionString);
    addEnvironment(context, "zipkin.collector.eventhub.eventHubConnectionString:" + dummyStorageConnectionString );
    addEnvironment(context, "zipkin.collector.eventhub.storageContainerName:" + storageContainerName);
    context.register(PropertyPlaceholderAutoConfiguration.class,
            EventHubCollectorAutoConfiguration.class,
            InMemoryConfiguration.class);
    context.refresh();

    EventHubCollector collector = context.getBean(EventHubCollector.class);
    assertNotNull(collector);
    assertEquals(storageContainerName, collector.getStorageContainerName());
}
 
開發者ID:aliostad,項目名稱:zipkin-collector-eventhub,代碼行數:19,代碼來源:EventHubCollectorAutoConfigurationTest.java

示例2: testCamelProducer

import org.springframework.context.annotation.AnnotationConfigApplicationContext; //導入依賴的package包/類
@Test
public void testCamelProducer() throws Exception {
    // Starting Spring context.
    try (GenericApplicationContext context = new AnnotationConfigApplicationContext(ExampleConfiguration.class)) {
        context.start();

        // Sending Camel message.
        CamelContext camel = context.getBean(CamelContext.class);
        ProducerTemplate producerTemplate = camel.createProducerTemplate();
        producerTemplate.sendBody("direct:start", "Send me to the Sponge");

        // Waiting for the engine to process an event.
        Engine engine = context.getBean(Engine.class);
        await().atMost(60, TimeUnit.SECONDS)
                .until(() -> engine.getOperations().getVariable(AtomicBoolean.class, "sentCamelMessage").get());

        assertFalse(engine.isError());
        context.stop();
    }
}
 
開發者ID:softelnet,項目名稱:sponge,代碼行數:21,代碼來源:SimpleCamelProducerTest.java

示例3: main

import org.springframework.context.annotation.AnnotationConfigApplicationContext; //導入依賴的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

示例4: init

import org.springframework.context.annotation.AnnotationConfigApplicationContext; //導入依賴的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

示例5: createAndFailWithCause

import org.springframework.context.annotation.AnnotationConfigApplicationContext; //導入依賴的package包/類
private void createAndFailWithCause(String cause) {
    try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext()) {
        context.register(MediaServicesAutoConfiguration.class);

        Exception exception = null;
        try {
            context.refresh();
        } catch (Exception e) {
            exception = e;
        }

        assertThat(exception).isNotNull();
        assertThat(exception).isExactlyInstanceOf(BeanCreationException.class);
        assertThat(exception.getCause().getCause().toString()).contains(cause);
    }
}
 
開發者ID:Microsoft,項目名稱:azure-spring-boot,代碼行數:17,代碼來源:MediaServicesAutoConfigurationTest.java

示例6: test

import org.springframework.context.annotation.AnnotationConfigApplicationContext; //導入依賴的package包/類
@Test
public void test() {
  AnnotationConfigApplicationContext context =
      new AnnotationConfigApplicationContext(this.getClass().getPackage().getName());
  Bean bean = context.getBean(Bean.class);

  Assert.assertEquals("aValue", bean.resolver.resolveStringValue("${a}"));
  try {
    bean.resolver.resolveStringValue("${b}");
    Assert.fail("must throw exception");
  } catch (IllegalArgumentException e) {
    Assert.assertEquals("Could not resolve placeholder 'b' in string value \"${b}\"", e.getMessage());
  }

  context.close();
}
 
開發者ID:apache,項目名稱:incubator-servicecomb-java-chassis,代碼行數:17,代碼來源:TestLastPropertyPlaceholderConfigurer.java

示例7: main

import org.springframework.context.annotation.AnnotationConfigApplicationContext; //導入依賴的package包/類
public static void main(String[] args) {
	 AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
	   context.register(BeanConfig.class);
   
	   System.out.println("application context loaded.");
        
       context.refresh();
       System.out.println("*********The empRec1 bean ***************");
       Employee empRec1A = (Employee) context.getBean("empRec1");
       System.out.println("instance A: " + empRec1A.hashCode());
       Employee empRec1B = (Employee) context.getBean("empRec1");
       System.out.println("instance B: " +empRec1B.hashCode());
       
       System.out.println("*********The empRec2 bean ***************");
       Employee empRec2A = (Employee) context.getBean("empRec2");
       System.out.println("instance A: " + empRec2A.hashCode());
       Employee empRec2B = (Employee) context.getBean("empRec2");
       System.out.println("instance B: " + empRec2B.hashCode());
       
       context.registerShutdownHook();
}
 
開發者ID:PacktPublishing,項目名稱:Spring-5.0-Cookbook,代碼行數:22,代碼來源:TestScopes.java

示例8: provideCollectorComponent_canSetCheckpointBatchSize

import org.springframework.context.annotation.AnnotationConfigApplicationContext; //導入依賴的package包/類
@Test
public void provideCollectorComponent_canSetCheckpointBatchSize() {

    int checkpointBatchSize = 1000;

    context = new AnnotationConfigApplicationContext();
    addEnvironment(context, "zipkin.collector.eventhub.storageConnectionString:" + dummyEventHubConnectionString);
    addEnvironment(context, "zipkin.collector.eventhub.eventHubConnectionString:" + dummyStorageConnectionString );
    addEnvironment(context, "zipkin.collector.eventhub.checkpoint-batch-size:" + checkpointBatchSize);
    context.register(PropertyPlaceholderAutoConfiguration.class,
            EventHubCollectorAutoConfiguration.class,
            InMemoryConfiguration.class);
    context.refresh();

    EventHubCollector collector = context.getBean(EventHubCollector.class);
    assertNotNull(collector);
    assertEquals(checkpointBatchSize, collector.getCheckpointBatchSize());
}
 
開發者ID:aliostad,項目名稱:zipkin-collector-eventhub,代碼行數:19,代碼來源:EventHubCollectorAutoConfigurationTest.java

示例9: enableSpringWebSessionConfiguresThings

import org.springframework.context.annotation.AnnotationConfigApplicationContext; //導入依賴的package包/類
@Test
public void enableSpringWebSessionConfiguresThings() {

	this.context = new AnnotationConfigApplicationContext();
	this.context.register(GoodConfig.class);
	this.context.refresh();

	WebSessionManager webSessionManagerFoundByType = this.context.getBean(WebSessionManager.class);
	Object webSessionManagerFoundByName = this.context.getBean(WebHttpHandlerBuilder.WEB_SESSION_MANAGER_BEAN_NAME);

	assertThat(webSessionManagerFoundByType).isNotNull();
	assertThat(webSessionManagerFoundByName).isNotNull();
	assertThat(webSessionManagerFoundByType).isEqualTo(webSessionManagerFoundByName);

	assertThat(this.context.getBean(ReactiveSessionRepository.class)).isNotNull();
}
 
開發者ID:spring-projects,項目名稱:spring-session-data-mongodb,代碼行數:17,代碼來源:ReactiveMongoWebSessionConfigurationTest.java

示例10: main

import org.springframework.context.annotation.AnnotationConfigApplicationContext; //導入依賴的package包/類
public static void main(String[] args) {
	
	AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Config.class);
	IToDoListDAO repository = context.getBean(IToDoListDAO.class);
	
       // fetch all ToDoLists
       System.out.println("ToDoLists found with findAll():");
       System.out.println("-------------------------------");
       for (ToDoList ToDoList : repository.findAll()) {
           System.out.println(ToDoList);
       }
       System.out.println();
	
	context.close();

}
 
開發者ID:Julien35,項目名稱:dev-courses,代碼行數:17,代碼來源:Main2.java

示例11: createStorageAccountWithInvalidConnectionString

import org.springframework.context.annotation.AnnotationConfigApplicationContext; //導入依賴的package包/類
@Test
public void createStorageAccountWithInvalidConnectionString() {
    System.setProperty(CONNECTION_STRING_PROPERTY, INVALID_CONNECTION_STRING);

    try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext()) {
        context.register(StorageAutoConfiguration.class);
        context.refresh();

        CloudStorageAccount cloudStorageAccount = null;
        try {
            cloudStorageAccount = context.getBean(CloudStorageAccount.class);
        } catch (Exception e) {
            assertThat(e).isExactlyInstanceOf(BeanCreationException.class);
        }

        assertThat(cloudStorageAccount).isNull();
    }

    System.clearProperty(CONNECTION_STRING_PROPERTY);
}
 
開發者ID:Microsoft,項目名稱:azure-spring-boot,代碼行數:21,代碼來源:StorageAutoConfigurationTest.java

示例12: verifyBeanCreationException

import org.springframework.context.annotation.AnnotationConfigApplicationContext; //導入依賴的package包/類
private void verifyBeanCreationException(String message, Class<?> beanClass) {
    try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext()) {
        Exception exception = null;
        try {
            context.register(ServiceBusAutoConfiguration.class);
            context.refresh();
            context.getBean(beanClass);
        } catch (Exception e) {
            exception = e;
        }

        assertThat(exception).isNotNull();
        assertThat(exception.getMessage()).contains(message);
        assertThat(exception).isExactlyInstanceOf(BeanCreationException.class);
    }
}
 
開發者ID:Microsoft,項目名稱:azure-spring-boot,代碼行數:17,代碼來源:ServiceBusAutoConfigurationTest.java

示例13: canSetAllProperties

import org.springframework.context.annotation.AnnotationConfigApplicationContext; //導入依賴的package包/類
@Test
public void canSetAllProperties() {
    PropertySettingUtil.setProperties();

    try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext()) {
        context.register(Config.class);
        context.refresh();
        final DocumentDBProperties properties = context.getBean(DocumentDBProperties.class);

        assertThat(properties.getUri()).isEqualTo(PropertySettingUtil.URI);
        assertThat(properties.getKey()).isEqualTo(PropertySettingUtil.KEY);
        assertThat(properties.getConsistencyLevel()).isEqualTo(PropertySettingUtil.CONSISTENCY_LEVEL);
        assertThat(properties.isAllowTelemetry()).isEqualTo(PropertySettingUtil.ALLOW_TELEMETRY_TRUE);
    }

    PropertySettingUtil.unsetProperties();
}
 
開發者ID:Microsoft,項目名稱:azure-spring-boot,代碼行數:18,代碼來源:DocumentDBPropertiesTest.java

示例14: httpBuilder

import org.springframework.context.annotation.AnnotationConfigApplicationContext; //導入依賴的package包/類
public static HttpServer httpBuilder (String connectionUrl) {
    try {
        URL url = new URL(connectionUrl);

        AnnotationConfigApplicationContext annotationConfigApplicationContext = new AnnotationConfigApplicationContext(SpringAnnotationConfig.class);

        ResourceConfig resourceConfig = new ResourceConfig();
        resourceConfig.register(RequestContextFilter.class);
        resourceConfig.property("contextConfig", annotationConfigApplicationContext);
        resourceConfig.register(RestSupport.class);

        URI baseUri = URI.create(url.getProtocol() + "://" + url.getAuthority());
        return  GrizzlyHttpServerFactory.createHttpServer(baseUri, resourceConfig, false);
    } catch (Exception e) {
        Assert.fail("Could'n parse configfile." + e.getMessage());
    }
    return null;
}
 
開發者ID:Comcast,項目名稱:redirector,代碼行數:19,代碼來源:WebServiceClientHelper.java

示例15: should_fail_on_invalid_queue_definitions

import org.springframework.context.annotation.AnnotationConfigApplicationContext; //導入依賴的package包/類
@Test
public void should_fail_on_invalid_queue_definitions() throws Exception {
    try {
        new AnnotationConfigApplicationContext(InvalidContext.class);
    } catch (IllegalArgumentException e) {
        assertThat(e.getMessage(), equalTo("unable to collect queue beans:" + System.lineSeparator() +
                "duplicate bean: name=testProducer2, class=SpringQueueProducer, queueId=test_queue" + System.lineSeparator() +
                "duplicate bean: name=testConsumer2, class=SpringQueueConsumer, queueId=test_queue" + System.lineSeparator() +
                "duplicate bean: name=testTransformer2, class=SpringTaskPayloadTransformer, queueId=test_queue" + System.lineSeparator() +
                "duplicate bean: name=testShardRouter2, class=SpringQueueShardRouter, queueId=test_queue" + System.lineSeparator() +
                "duplicate bean: name=springTaskLifecycleListener2, class=SpringTaskLifecycleListener, queueId=test_queue" + System.lineSeparator() +
                "duplicate bean: name=springThreadLifecycleListener2, class=SpringThreadLifecycleListener, queueId=test_queue" + System.lineSeparator() +
                "duplicate bean: name=springQueueExternalExecutor2, class=SpringQueueExternalExecutor, queueId=test_queue"));
        return;
    }
    Assert.fail("context should not be constructed");
}
 
開發者ID:yandex-money,項目名稱:db-queue,代碼行數:18,代碼來源:SpringQueueCollectorTest.java


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