本文整理汇总了Java中org.springframework.context.annotation.AnnotationBeanNameGenerator类的典型用法代码示例。如果您正苦于以下问题:Java AnnotationBeanNameGenerator类的具体用法?Java AnnotationBeanNameGenerator怎么用?Java AnnotationBeanNameGenerator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AnnotationBeanNameGenerator类属于org.springframework.context.annotation包,在下文中一共展示了AnnotationBeanNameGenerator类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: registerOuterConfig_withBeanNameGenerator
import org.springframework.context.annotation.AnnotationBeanNameGenerator; //导入依赖的package包/类
@Test
public void registerOuterConfig_withBeanNameGenerator() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.setBeanNameGenerator(new AnnotationBeanNameGenerator() {
@Override
public String generateBeanName(
BeanDefinition definition, BeanDefinitionRegistry registry) {
return "custom-" + super.generateBeanName(definition, registry);
}
});
ctx.register(A.class);
ctx.refresh();
assertThat(ctx.containsBean("custom-outer"), is(true));
assertThat(ctx.containsBean("custom-imported"), is(true));
assertThat(ctx.containsBean("custom-nested"), is(true));
assertThat(ctx.containsBean("nestedBean"), is(true));
}
示例2: postProcessBeanDefinitionRegistry
import org.springframework.context.annotation.AnnotationBeanNameGenerator; //导入依赖的package包/类
@Override
public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException {
if (registry.containsBeanDefinition("restServer")) {
BeanDefinition beanDefinition = registry.getBeanDefinition("restServer");
ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(false);
scanner.addIncludeFilter(new AnnotationTypeFilter(Path.class));
BeanNameGenerator nameGenerator = new AnnotationBeanNameGenerator();
List<RuntimeBeanReference> beanNames = new ManagedList<>();
for (BeanDefinition definition : scanner.findCandidateComponents("net.techreadiness")) {
String beanName = nameGenerator.generateBeanName(definition, registry);
beanNames.add(new RuntimeBeanReference(beanName));
}
beanNames.addAll((Collection<? extends RuntimeBeanReference>) beanDefinition.getPropertyValues()
.getPropertyValue("serviceBeans").getValue());
beanDefinition.getPropertyValues().add("serviceBeans", beanNames);
}
}
示例3: withBeanNameGenerator
import org.springframework.context.annotation.AnnotationBeanNameGenerator; //导入依赖的package包/类
@Test
@SuppressWarnings("resource")
public void withBeanNameGenerator() {
AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
ctx.setBeanNameGenerator(new AnnotationBeanNameGenerator() {
@Override
public String generateBeanName(BeanDefinition definition,
BeanDefinitionRegistry registry) {
return "custom-" + super.generateBeanName(definition, registry);
}
});
ctx.setConfigLocation(Config.class.getName());
ctx.refresh();
assertThat(ctx.containsBean("custom-myConfig"), is(true));
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:16,代码来源:AnnotationConfigWebApplicationContextTests.java
示例4: withBeanNameGenerator
import org.springframework.context.annotation.AnnotationBeanNameGenerator; //导入依赖的package包/类
@Test
public void withBeanNameGenerator() {
AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
ctx.setBeanNameGenerator(new AnnotationBeanNameGenerator() {
@Override
public String generateBeanName(BeanDefinition definition,
BeanDefinitionRegistry registry) {
return "custom-" + super.generateBeanName(definition, registry);
}
});
ctx.setConfigLocation(Config.class.getName());
ctx.refresh();
assertThat(ctx.containsBean("custom-myConfig"), is(true));
}