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


Java AnnotationConfigApplicationContext.getBean方法代码示例

本文整理汇总了Java中org.springframework.context.annotation.AnnotationConfigApplicationContext.getBean方法的典型用法代码示例。如果您正苦于以下问题:Java AnnotationConfigApplicationContext.getBean方法的具体用法?Java AnnotationConfigApplicationContext.getBean怎么用?Java AnnotationConfigApplicationContext.getBean使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.context.annotation.AnnotationConfigApplicationContext的用法示例。


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

示例1: provideCollectorComponent_canSetConsumerGroupName

import org.springframework.context.annotation.AnnotationConfigApplicationContext; //导入方法依赖的package包/类
@Test
public void provideCollectorComponent_canSetConsumerGroupName() {

    String consumerGroupName = "pashmak";

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

    EventHubCollector collector = context.getBean(EventHubCollector.class);
    assertNotNull(collector);
    assertEquals(consumerGroupName, collector.getConsumerGroupName());
}
 
开发者ID:aliostad,项目名称:zipkin-collector-eventhub,代码行数:19,代码来源:EventHubCollectorAutoConfigurationTest.java

示例2: setUp

import org.springframework.context.annotation.AnnotationConfigApplicationContext; //导入方法依赖的package包/类
@Before
public void setUp() throws IOException {
    AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
    applicationContext.register(TarantoolConfiguration.class);
    DockerPort dockerPort = docker.containers()
            .container("tarantool")
            .port(3301);
    ImmutableMap<String, Object> env = ImmutableMap.of("tarantoolPort", dockerPort.getExternalPort());
    applicationContext.getEnvironment().getPropertySources()
            .addFirst(new MapPropertySource("rule", env));
    applicationContext.refresh();

    TarantoolClientOps bean = (TarantoolClientOps) applicationContext.getBean("tarantoolSyncOps");
    String eval = IOUtils.toString(RepositoryIntegrationTests.class.getResource("/init.lua"));
    bean.eval(eval);
    //
    userRepository = applicationContext.getBean(UserRepository.class);
    userRepository.deleteAll();

    logEntryRepository = applicationContext.getBean(LogEntryRepository.class);
    logEntryRepository.deleteAll();

    addressRepository = applicationContext.getBean(AddressRepository.class);
    addressRepository.deleteAll();
}
 
开发者ID:saladinkzn,项目名称:spring-data-tarantool,代码行数:26,代码来源:RepositoryIntegrationTests.java

示例3: main

import org.springframework.context.annotation.AnnotationConfigApplicationContext; //导入方法依赖的package包/类
public static void main(String[] args) {

		AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
		ctx.register(ApplicationConfig.class);
		ctx.refresh();
		System.out.println("Spring Framework Version: " + SpringVersion.getVersion());
		System.out.println("Spring Boot Version: " + SpringBootVersion.getVersion());
		JpaUI ui = ctx.getBean(JpaUI.class);
		ui.init();
		ctx.close();
	}
 
开发者ID:mintster,项目名称:nixmash-blog,代码行数:12,代码来源:JpaLauncher.java

示例4: main

import org.springframework.context.annotation.AnnotationConfigApplicationContext; //导入方法依赖的package包/类
public static void main(String[] args) {
	AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
			PrePostConfig.class);

	BeanWayService beanWayService = context.getBean(BeanWayService.class);
	JSR250WayService jsr250WayService = context.getBean(JSR250WayService.class);

	context.close();
}
 
开发者ID:longjiazuo,项目名称:spring4.x-project,代码行数:10,代码来源:Main.java

示例5: main

import org.springframework.context.annotation.AnnotationConfigApplicationContext; //导入方法依赖的package包/类
/**
 * @param args
 */
public static void main(String[] args) {
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
                        PrePostConfig.class);
        context.getBean(BeanWayService.class);
        context.getBean(Jsr250WayService.class);
        context.close();
}
 
开发者ID:zhazhapan,项目名称:hello-spring,代码行数:11,代码来源:Main.java

示例6: 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 empRec1 = (Employee) context.getBean("empRec1");
       
       System.out.println("*********The empRec2 bean ***************");
       Employee empRec2 = (Employee) context.getBean("empRec2");
       Department dept2 = empRec2.getDept();
       System.out.println("First Name: " + empRec2.getFirstName());
       System.out.println("Last Name: " + empRec2.getLastName());
       System.out.println("Birthdate: " + empRec2.getBirthdate());
       System.out.println("Salary: " + empRec2.getSalary());
       System.out.println("Dept. Name: " + dept2.getDeptName());
       
       System.out.println("*********The empRec3 bean ***************");
       Employee empRec3 = (Employee) context.getBean("empRec3");
       Department dept3 = empRec3.getDept();
       System.out.println("First Name: " + empRec3.getFirstName());
       System.out.println("Last Name: " + empRec3.getLastName());
       System.out.println("Birthdate: " + empRec3.getBirthdate());
       System.out.println("Salary: " + empRec3.getSalary());
       System.out.println("Dept. Name: " + dept3.getDeptName());
       
       System.out.println("*********The empRec4 bean ***************");
       Employee empRec4 = (Employee) context.getBean("empRec4");
       Department dept4 = empRec4.getDept();
       System.out.println("First Name: " + empRec4.getFirstName());
       System.out.println("Last Name: " + empRec4.getLastName());
       System.out.println("Birthdate: " + empRec4.getBirthdate());
       System.out.println("Salary: " + empRec4.getSalary());
       System.out.println("Dept. Name: " + dept4.getDeptName());
       
       context.registerShutdownHook();
}
 
开发者ID:PacktPublishing,项目名称:Spring-5.0-Cookbook,代码行数:40,代码来源:TestBeans.java

示例7: testSpringAutoStartupFalse

import org.springframework.context.annotation.AnnotationConfigApplicationContext; //导入方法依赖的package包/类
@Test
public void testSpringAutoStartupFalse() throws InterruptedException {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(TestConfigAutoStartupFalse.class);
    ctx.start();

    try {
        Engine engine = ctx.getBean(Engine.class);

        assertFalse(engine.isRunning());
        assertFalse(engine.isError());
    } finally {
        ctx.close();
    }
}
 
开发者ID:softelnet,项目名称:sponge,代码行数:15,代码来源:SpringAutoStartupTest.java

示例8: vocabularyLocationCanBeCustomized

import org.springframework.context.annotation.AnnotationConfigApplicationContext; //导入方法依赖的package包/类
@Test
public void vocabularyLocationCanBeCustomized() {
	AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
	EnvironmentTestUtils.addEnvironment(context, "inception.vocabularyLocation:/remote");
	context.register(Conf.class);
	context.refresh();
	TwitterSentimentProcessorProperties properties = context.getBean(TwitterSentimentProcessorProperties.class);
	assertThat(properties.getVocabularyLocation(), equalTo(context.getResource("/remote")));
}
 
开发者ID:tzolov,项目名称:tensorflow-spring-cloud-stream-app-starters,代码行数:10,代码来源:TwitterSentimentProcessorPropertiesTest.java

示例9: setUp

import org.springframework.context.annotation.AnnotationConfigApplicationContext; //导入方法依赖的package包/类
@Before
public void setUp() {
    context = new AnnotationConfigApplicationContext(SearchConfiguration.class);
    context.start();

    repository = context.getBean(GaeSearchRepository.class);

    repository.save(new SearchData(1L, 10, "Baz"));
}
 
开发者ID:snowdrop,项目名称:spring-data-snowdrop,代码行数:10,代码来源:SearchTest.java

示例10: should_collect_all_bean_definitions

import org.springframework.context.annotation.AnnotationConfigApplicationContext; //导入方法依赖的package包/类
@Test
public void should_collect_all_bean_definitions() throws Exception {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ValidContext.class);
    SpringQueueCollector collector = context.getBean(SpringQueueCollector.class);
    assertThat(collector.getProducers().size(), equalTo(2));
    assertThat(collector.getConsumers().size(), equalTo(2));
    assertThat(collector.getTransformers().size(), equalTo(2));
    assertThat(collector.getShardRouters().size(), equalTo(2));
    assertThat(collector.getTaskListeners().size(), equalTo(2));
    assertThat(collector.getThreadListeners().size(), equalTo(2));
    assertThat(collector.getExecutors().size(), equalTo(2));
}
 
开发者ID:yandex-money,项目名称:db-queue,代码行数:13,代码来源:SpringQueueCollectorTest.java

示例11: main

import org.springframework.context.annotation.AnnotationConfigApplicationContext; //导入方法依赖的package包/类
public static void main(String[] args) {
	AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(TaskExecutorConfig.class);
	AsyncTaskService asyncTaskService = context.getBean(AsyncTaskService.class);
	int nums = 10;
	for (int i = 0; i < nums; i++) {
		asyncTaskService.executeAsyncTask(i);
		asyncTaskService.executeAsyncTaskPlus(i);
	}
	context.close();
}
 
开发者ID:zhazhapan,项目名称:hello-spring,代码行数:11,代码来源:Main.java

示例12: main

import org.springframework.context.annotation.AnnotationConfigApplicationContext; //导入方法依赖的package包/类
public static void main(String[] args) {
	AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ScopeConfig.class);
	DemoSingletonService s1 = context.getBean(DemoSingletonService.class);
	DemoSingletonService s2 = context.getBean(DemoSingletonService.class);
	DemoPrototypeService p1 = context.getBean(DemoPrototypeService.class);
	DemoPrototypeService p2 = context.getBean(DemoPrototypeService.class);

	System.out.println("s1与s2是否相等:" + s1.equals(s2));
	System.out.println("p1与p2是否相等:" + p1.equals(p2));

	context.close();
}
 
开发者ID:zhazhapan,项目名称:hello-spring,代码行数:13,代码来源:Main.java

示例13: check

import org.springframework.context.annotation.AnnotationConfigApplicationContext; //导入方法依赖的package包/类
private void check(int expectedTimeout, int expectedBatch, Class<?>... annotatedClasses) {
  AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(annotatedClasses);

  TestJavaConfigBean bean = context.getBean(TestJavaConfigBean.class);

  assertEquals(expectedTimeout, bean.getTimeout());
  assertEquals(expectedBatch, bean.getBatch());
}
 
开发者ID:dewey-its,项目名称:apollo-custom,代码行数:9,代码来源:JavaConfigPlaceholderTest.java

示例14: main

import org.springframework.context.annotation.AnnotationConfigApplicationContext; //导入方法依赖的package包/类
public static void main(String[] args) {
	AnnotationConfigApplicationContext context =
			new AnnotationConfigApplicationContext();
			context.register(AppConfiguration.class);
			context.refresh();
	ReportGenerator generator = (ReportGenerator) context.getBean("generator1");
	generator.format();
}
 
开发者ID:PawelBogdan,项目名称:BecomeJavaHero,代码行数:9,代码来源:App.java

示例15: main

import org.springframework.context.annotation.AnnotationConfigApplicationContext; //导入方法依赖的package包/类
public static void main(String[] args) {
	AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(DemoConfig.class);
	AnnoDemoService demoService = context.getBean(AnnoDemoService.class);
	demoService.outputResult();
	context.close();
}
 
开发者ID:zhazhapan,项目名称:hello-spring,代码行数:7,代码来源:Main.java


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