當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。