org.springframework.beans.factory.support.BeanDefinitionReader.loadBeanDefinitions()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(11.8k)|赞(0)|评价(0)|浏览(60)

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

BeanDefinitionReader.loadBeanDefinitions介绍

[英]Load bean definitions from the specified resource location.

The location can also be a location pattern, provided that the ResourceLoader of this bean definition reader is a ResourcePatternResolver.
[中]

代码示例

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

reader.loadBeanDefinitions(resource);
});

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

/**
 * Load bean definitions into the supplied {@link GenericApplicationContext context}
 * from the locations or classes in the supplied {@code MergedContextConfiguration}.
 *
 * <p>The default implementation delegates to the {@link BeanDefinitionReader}
 * returned by {@link #createBeanDefinitionReader(GenericApplicationContext)} to
 * {@link BeanDefinitionReader#loadBeanDefinitions(String) load} the
 * bean definitions.
 *
 * <p>Subclasses must provide an appropriate implementation of
 * {@link #createBeanDefinitionReader(GenericApplicationContext)}. Alternatively subclasses
 * may provide a <em>no-op</em> implementation of {@code createBeanDefinitionReader()}
 * and override this method to provide a custom strategy for loading or
 * registering bean definitions.
 *
 * @param context the context into which the bean definitions should be loaded
 * @param mergedConfig the merged context configuration
 * @since 3.1
 * @see #loadContext(MergedContextConfiguration)
 */
protected void loadBeanDefinitions(GenericApplicationContext context, MergedContextConfiguration mergedConfig) {
  createBeanDefinitionReader(context).loadBeanDefinitions(mergedConfig.getLocations());
}

代码示例来源:origin: org.springframework.boot/spring-boot

private int load(Resource source) {
  if (source.getFilename().endsWith(".groovy")) {
    if (this.groovyReader == null) {
      throw new BeanDefinitionStoreException(
          "Cannot load Groovy beans without Groovy on classpath");
    }
    return this.groovyReader.loadBeanDefinitions(source);
  }
  return this.xmlReader.loadBeanDefinitions(source);
}

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

@Before
public void setUp() throws Exception {
  BeanDefinitionReader reader = new XmlBeanDefinitionReader(this.beanFactory);
  reader.loadBeanDefinitions(new ClassPathResource("collectionMerging.xml", getClass()));
}

代码示例来源:origin: HotswapProjects/HotswapAgent

/**
 *  reload bean from xml defination
 *  @param url url of xml
 */
public void reloadBeanFromXml(URL url) {
  LOGGER.info("reloading xml file: " + url);
  // this will call registerBeanDefinition which in turn call resetBeanDefinition to destroy singleton
  // maybe should use watchResourceClassLoader.getResource?
  this.reader.loadBeanDefinitions(new FileSystemResource(url.getPath()));
  // spring won't rebuild dependency map if injectionMetadataCache is not cleared
  // which lead to singletons depend on beans in xml won't be destroy and recreate, may be a spring bug?
  ResetBeanPostProcessorCaches.reset(maybeRegistryToBeanFactory());
  ProxyReplacer.clearAllProxies();
  reloadFlag = false;
}

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

@Test
public void testInterfaceWithOneQualifiedFactoryAndOneQualifiedBean() {
  StaticApplicationContext context = new StaticApplicationContext();
  BeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
  reader.loadBeanDefinitions(CONFIG_LOCATION);
}

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

prepareContext(context);
customizeBeanFactory(context.getDefaultListableBeanFactory());
createBeanDefinitionReader(context).loadBeanDefinitions(locations);
AnnotationConfigUtils.registerAnnotationConfigProcessors(context);
customizeContext(context);

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

@Test
public void testQualifiedByAttributesFailsWithoutCustomQualifierRegistered() {
  StaticApplicationContext context = new StaticApplicationContext();
  BeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
  reader.loadBeanDefinitions(CONFIG_LOCATION);
  context.registerSingleton("testBean", QualifiedByAttributesTestBean.class);
  try {
    context.refresh();
    fail("should have thrown a BeanCreationException");
  }
  catch (BeanCreationException e) {
    assertTrue(e.getMessage().contains("found 6"));
  }
}

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

@Test
public void testNonQualifiedFieldFails() {
  StaticApplicationContext context = new StaticApplicationContext();
  BeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
  reader.loadBeanDefinitions(CONFIG_LOCATION);
  context.registerSingleton("testBean", NonQualifiedTestBean.class);
  try {
    context.refresh();
    fail("Should have thrown a BeanCreationException");
  }
  catch (BeanCreationException e) {
    assertTrue(e.getMessage().contains("found 6"));
  }
}

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

@Test
public void testQualifiedByBeanName() {
  StaticApplicationContext context = new StaticApplicationContext();
  BeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
  reader.loadBeanDefinitions(CONFIG_LOCATION);
  context.registerSingleton("testBean", QualifiedByBeanNameTestBean.class);
  context.refresh();
  QualifiedByBeanNameTestBean testBean = (QualifiedByBeanNameTestBean) context.getBean("testBean");
  Person person = testBean.getLarry();
  assertEquals("LarryBean", person.getName());
  assertTrue(testBean.myProps != null && testBean.myProps.isEmpty());
}

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

@Test
public void testQualifiedByCustomValue() {
  StaticApplicationContext context = new StaticApplicationContext();
  BeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
  reader.loadBeanDefinitions(CONFIG_LOCATION);
  context.registerSingleton("testBean", QualifiedByCustomValueTestBean.class);
  context.refresh();
  QualifiedByCustomValueTestBean testBean = (QualifiedByCustomValueTestBean) context.getBean("testBean");
  Person person = testBean.getCurly();
  assertEquals("Curly", person.getName());
}

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

@Test
public void testQualifiedByAnnotationValue() {
  StaticApplicationContext context = new StaticApplicationContext();
  BeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
  reader.loadBeanDefinitions(CONFIG_LOCATION);
  context.registerSingleton("testBean", QualifiedByAnnotationValueTestBean.class);
  context.refresh();
  QualifiedByAnnotationValueTestBean testBean = (QualifiedByAnnotationValueTestBean) context.getBean("testBean");
  Person person = testBean.getLarry();
  assertEquals("LarrySpecial", person.getName());
}

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

@Test
public void testQualifiedByParameterName() {
  StaticApplicationContext context = new StaticApplicationContext();
  BeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
  reader.loadBeanDefinitions(CONFIG_LOCATION);
  context.registerSingleton("testBean", QualifiedByParameterNameTestBean.class);
  context.refresh();
  QualifiedByParameterNameTestBean testBean = (QualifiedByParameterNameTestBean) context.getBean("testBean");
  Person person = testBean.getLarry();
  assertEquals("LarryBean", person.getName());
}

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

@Test
public void testQualifiedByValue() {
  StaticApplicationContext context = new StaticApplicationContext();
  BeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
  reader.loadBeanDefinitions(CONFIG_LOCATION);
  context.registerSingleton("testBean", QualifiedByValueTestBean.class);
  context.refresh();
  QualifiedByValueTestBean testBean = (QualifiedByValueTestBean) context.getBean("testBean");
  Person person = testBean.getLarry();
  assertEquals("Larry", person.getName());
}

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

@Test
public void testQualifiedByAlias() {
  StaticApplicationContext context = new StaticApplicationContext();
  BeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
  reader.loadBeanDefinitions(CONFIG_LOCATION);
  context.registerSingleton("testBean", QualifiedByAliasTestBean.class);
  context.refresh();
  QualifiedByAliasTestBean testBean = (QualifiedByAliasTestBean) context.getBean("testBean");
  Person person = testBean.getStooge();
  assertEquals("LarryBean", person.getName());
}

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

@Test
public void testQualifiedByAnnotation() {
  StaticApplicationContext context = new StaticApplicationContext();
  BeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
  reader.loadBeanDefinitions(CONFIG_LOCATION);
  context.registerSingleton("testBean", QualifiedByAnnotationTestBean.class);
  context.refresh();
  QualifiedByAnnotationTestBean testBean = (QualifiedByAnnotationTestBean) context.getBean("testBean");
  Person person = testBean.getLarry();
  assertEquals("LarrySpecial", person.getName());
}

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

@Test
public void testQualifiedByFieldName() {
  StaticApplicationContext context = new StaticApplicationContext();
  BeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
  reader.loadBeanDefinitions(CONFIG_LOCATION);
  context.registerSingleton("testBean", QualifiedByFieldNameTestBean.class);
  context.refresh();
  QualifiedByFieldNameTestBean testBean = (QualifiedByFieldNameTestBean) context.getBean("testBean");
  Person person = testBean.getLarry();
  assertEquals("LarryBean", person.getName());
}

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

@Test
public void testCustomResolver() {
  DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
  BeanDefinitionReader reader = new XmlBeanDefinitionReader(bf);
  reader.loadBeanDefinitions(CONTEXT);
  CustomAutowireConfigurer cac = new CustomAutowireConfigurer();
  CustomResolver customResolver = new CustomResolver();
  bf.setAutowireCandidateResolver(customResolver);
  cac.postProcessBeanFactory(bf);
  TestBean testBean = (TestBean) bf.getBean("testBean");
  assertEquals("#1!", testBean.getName());
}

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

@Test
public void testQualifiedByAttributesWithCustomQualifierRegistered() {
  StaticApplicationContext context = new StaticApplicationContext();
  BeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
  reader.loadBeanDefinitions(CONFIG_LOCATION);
  QualifierAnnotationAutowireCandidateResolver resolver = (QualifierAnnotationAutowireCandidateResolver)
      context.getDefaultListableBeanFactory().getAutowireCandidateResolver();
  resolver.addQualifierType(MultipleAttributeQualifier.class);
  context.registerSingleton("testBean", MultiQualifierClient.class);
  context.refresh();
  MultiQualifierClient testBean = (MultiQualifierClient) context.getBean("testBean");
  assertNotNull( testBean.factoryTheta);
  assertNotNull( testBean.implTheta);
}

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

@Test
public void testQualifiedByParentValue() {
  StaticApplicationContext parent = new StaticApplicationContext();
  GenericBeanDefinition parentLarry = new GenericBeanDefinition();
  parentLarry.setBeanClass(Person.class);
  parentLarry.getPropertyValues().add("name", "ParentLarry");
  parentLarry.addQualifier(new AutowireCandidateQualifier(Qualifier.class, "parentLarry"));
  parent.registerBeanDefinition("someLarry", parentLarry);
  GenericBeanDefinition otherLarry = new GenericBeanDefinition();
  otherLarry.setBeanClass(Person.class);
  otherLarry.getPropertyValues().add("name", "OtherLarry");
  otherLarry.addQualifier(new AutowireCandidateQualifier(Qualifier.class, "otherLarry"));
  parent.registerBeanDefinition("someOtherLarry", otherLarry);
  parent.refresh();
  StaticApplicationContext context = new StaticApplicationContext(parent);
  BeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
  reader.loadBeanDefinitions(CONFIG_LOCATION);
  context.registerSingleton("testBean", QualifiedByParentValueTestBean.class);
  context.refresh();
  QualifiedByParentValueTestBean testBean = (QualifiedByParentValueTestBean) context.getBean("testBean");
  Person person = testBean.getLarry();
  assertEquals("ParentLarry", person.getName());
}

相关文章

微信公众号

最新文章

更多