本文整理了Java中org.springframework.context.annotation.AnnotationConfigApplicationContext.getBeanDefinition()
方法的一些代码示例,展示了AnnotationConfigApplicationContext.getBeanDefinition()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。AnnotationConfigApplicationContext.getBeanDefinition()
方法的具体详情如下:
包路径:org.springframework.context.annotation.AnnotationConfigApplicationContext
类名称:AnnotationConfigApplicationContext
方法名:getBeanDefinition
暂无
代码示例来源:origin: spring-projects/spring-framework
@Test
public void onBeanMethod() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(Config.class);
ctx.refresh();
assertThat("Expected bean to have ROLE_APPLICATION",
ctx.getBeanDefinition("foo").getRole(), is(BeanDefinition.ROLE_APPLICATION));
assertThat(ctx.getBeanDefinition("foo").getDescription(), is((Object) null));
assertThat("Expected bean to have ROLE_INFRASTRUCTURE",
ctx.getBeanDefinition("bar").getRole(), is(BeanDefinition.ROLE_INFRASTRUCTURE));
assertThat(ctx.getBeanDefinition("bar").getDescription(), is("A Bean method with a role"));
}
代码示例来源:origin: org.talend.daikon/service-common
@Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
// Create the annotation-based context
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context, false);
scanner.addIncludeFilter(new ServiceTypeFilter());
final String basePackage = StringUtils.substringBeforeLast(importingClassMetadata.getClassName(), ".");
scanner.scan(basePackage);
// Import scanned services in current registry
final String[] names = context.getBeanDefinitionNames();
for (String name : names) {
final BeanDefinition definition = context.getBeanDefinition(name);
registry.registerBeanDefinition(name, definition);
}
}
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void onComponentClass() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(ComponentWithoutRole.class, ComponentWithRole.class);
ctx.refresh();
assertThat("Expected bean to have ROLE_APPLICATION",
ctx.getBeanDefinition("componentWithoutRole").getRole(), is(BeanDefinition.ROLE_APPLICATION));
assertThat(ctx.getBeanDefinition("componentWithoutRole").getDescription(), is((Object) null));
assertThat("Expected bean to have ROLE_INFRASTRUCTURE",
ctx.getBeanDefinition("componentWithRole").getRole(), is(BeanDefinition.ROLE_INFRASTRUCTURE));
assertThat(ctx.getBeanDefinition("componentWithRole").getDescription(), is("A Component with a role"));
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void viaComponentScanning() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.scan("org.springframework.context.annotation.role");
ctx.refresh();
assertThat("Expected bean to have ROLE_APPLICATION",
ctx.getBeanDefinition("componentWithoutRole").getRole(), is(BeanDefinition.ROLE_APPLICATION));
assertThat(ctx.getBeanDefinition("componentWithoutRole").getDescription(), is((Object) null));
assertThat("Expected bean to have ROLE_INFRASTRUCTURE",
ctx.getBeanDefinition("componentWithRole").getRole(), is(BeanDefinition.ROLE_INFRASTRUCTURE));
assertThat(ctx.getBeanDefinition("componentWithRole").getDescription(), is("A Component with a role"));
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void providesBeanMethodBeanDefinition() throws Exception {
AnnotationConfigApplicationContext context= new AnnotationConfigApplicationContext(Conf.class);
BeanDefinition beanDefinition = context.getBeanDefinition("myBean");
assertThat("should provide AnnotatedBeanDefinition", beanDefinition, instanceOf(AnnotatedBeanDefinition.class));
Map<String, Object> annotationAttributes =
((AnnotatedBeanDefinition) beanDefinition).getFactoryMethodMetadata().getAnnotationAttributes(MyAnnotation.class.getName());
assertThat(annotationAttributes.get("value"), equalTo("test"));
context.close();
}
代码示例来源:origin: stackoverflow.com
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(AppConfig.class);
ctx.refresh();
BeanDefinition javaConfigBeanDefinition = ctx.getBeanDefinition("a");
System.out.println("Creation class for a=" + javaConfigBeanDefinition.getResourceDescription());
BeanDefinition xmlBeanDefinition = ctx.getBeanDefinition("xmlBean");
System.out.println("Creation XML file for xmlBean=" + xmlBeanDefinition.getResourceDescription());
代码示例来源:origin: stackoverflow.com
public void testBeanDefinitionOverriding() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(Config.class);
BeanDefinition bd = ctx.getBeanDefinition("bean");
Assert.assertEquals("doInit", bd.getDependsOn()[0]);
代码示例来源:origin: sixhours-team/memcached-spring-boot
@Test
public void whenRefreshAutoConfigurationThenRefreshConfigurationLoaded() {
loadContext(CacheWithRefreshAutoConfiguration.class);
assertThat(this.applicationContext
.getBeanDefinition("scopedTarget.cacheManager").getScope()).isEqualTo("refresh");
}
内容来源于网络,如有侵权,请联系作者删除!