org.springframework.context.annotation.AnnotationConfigApplicationContext.getBeanNamesForType()方法的使用及代码示例

x33g5p2x  于2022-01-15 转载在 其他  
字(2.7k)|赞(0)|评价(0)|浏览(120)

本文整理了Java中org.springframework.context.annotation.AnnotationConfigApplicationContext.getBeanNamesForType()方法的一些代码示例,展示了AnnotationConfigApplicationContext.getBeanNamesForType()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。AnnotationConfigApplicationContext.getBeanNamesForType()方法的具体详情如下:
包路径:org.springframework.context.annotation.AnnotationConfigApplicationContext
类名称:AnnotationConfigApplicationContext
方法名:getBeanNamesForType

AnnotationConfigApplicationContext.getBeanNamesForType介绍

暂无

代码示例

代码示例来源:origin: spring-projects/spring-framework

/**
 * Test that values supplied to @Configuration(value="...") are propagated as the
 * bean name for the configuration class even in the case of inclusion via @Import
 * or in the case of automatic registration via nesting
 */
@Test
public void reproSpr9023() {
  AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
  ctx.register(B.class);
  ctx.refresh();
  System.out.println(ctx.getBeanFactory());
  assertThat(ctx.getBeanNamesForType(B.class)[0], is("config-b"));
  assertThat(ctx.getBeanNamesForType(A.class)[0], is("config-a"));
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void individualBeanWithNullReturningSupplier() {
  AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
  context.registerBean("a", BeanA.class, () -> null);
  context.registerBean("b", BeanB.class, BeanB::new);
  context.registerBean("c", BeanC.class, BeanC::new);
  context.refresh();
  assertTrue(ObjectUtils.containsElement(context.getBeanNamesForType(BeanA.class), "a"));
  assertTrue(ObjectUtils.containsElement(context.getBeanNamesForType(BeanB.class), "b"));
  assertTrue(ObjectUtils.containsElement(context.getBeanNamesForType(BeanC.class), "c"));
  assertTrue(context.getBeansOfType(BeanA.class).isEmpty());
  assertSame(context.getBean(BeanB.class), context.getBeansOfType(BeanB.class).values().iterator().next());
  assertSame(context.getBean(BeanC.class), context.getBeansOfType(BeanC.class).values().iterator().next());
}

代码示例来源:origin: domix/jade4j-spring-boot-starter

@Test
@Ignore
public void renderNonWebAppTemplate() throws Exception {
 AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
  Jade4JAutoConfiguration.class,
  PropertyPlaceholderAutoConfiguration.class);
 assertEquals(0, context.getBeanNamesForType(ViewResolver.class).length);
 try {
  JadeConfiguration engine = this.context.getBean(JadeConfiguration.class);
  JadeTemplate template = engine.getTemplate("demo.jade");
  Map<String, Object> params = params();
  String result = engine.renderTemplate(template, params);
  assertThat(result, containsString("With user"));
 } finally {
  context.close();
 }
}

相关文章

微信公众号

最新文章

更多

AnnotationConfigApplicationContext类方法