当前位置: 首页>>代码示例>>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;未经允许,请勿转载。