Search in sources :

Example 1 with PropertiesBeanDefinitionReader

use of cn.taketoday.beans.factory.support.PropertiesBeanDefinitionReader in project today-framework by TAKETODAY.

the class StaticApplicationContextMulticasterTests method createContext.

@Override
protected ConfigurableApplicationContext createContext() throws Exception {
    StaticApplicationContext parent = new StaticApplicationContext();
    Map<String, String> m = new HashMap<>();
    m.put("name", "Roderick");
    parent.registerPrototype("rod", TestBean.class, new PropertyValues(m));
    m.put("name", "Albert");
    parent.registerPrototype("father", TestBean.class, new PropertyValues(m));
    parent.registerSingleton(StaticApplicationContext.APPLICATION_EVENT_MULTICASTER_BEAN_NAME, TestApplicationEventMulticaster.class, null);
    parent.refresh();
    parent.addApplicationListener(parentListener);
    parent.getStaticMessageSource().addMessage("code1", Locale.getDefault(), "message1");
    this.sac = new StaticApplicationContext(parent);
    sac.registerSingleton("beanThatListens", BeanThatListens.class, new PropertyValues());
    sac.registerSingleton("aca", ACATester.class, new PropertyValues());
    sac.registerPrototype("aca-prototype", ACATester.class, new PropertyValues());
    PropertiesBeanDefinitionReader reader = new PropertiesBeanDefinitionReader(sac.getBeanFactory());
    Resource resource = new ClassPathResource("testBeans.properties", getClass());
    reader.loadBeanDefinitions(new EncodedResource(resource, "ISO-8859-1"));
    sac.refresh();
    sac.addApplicationListener(listener);
    sac.getStaticMessageSource().addMessage("code2", Locale.getDefault(), "message2");
    return sac;
}
Also used : PropertyValues(cn.taketoday.beans.PropertyValues) HashMap(java.util.HashMap) PropertiesBeanDefinitionReader(cn.taketoday.beans.factory.support.PropertiesBeanDefinitionReader) Resource(cn.taketoday.core.io.Resource) EncodedResource(cn.taketoday.core.io.EncodedResource) ClassPathResource(cn.taketoday.core.io.ClassPathResource) ClassPathResource(cn.taketoday.core.io.ClassPathResource) EncodedResource(cn.taketoday.core.io.EncodedResource)

Example 2 with PropertiesBeanDefinitionReader

use of cn.taketoday.beans.factory.support.PropertiesBeanDefinitionReader in project today-infrastructure by TAKETODAY.

the class StaticApplicationContextMulticasterTests method createContext.

@Override
protected ConfigurableApplicationContext createContext() throws Exception {
    StaticApplicationContext parent = new StaticApplicationContext();
    Map<String, String> m = new HashMap<>();
    m.put("name", "Roderick");
    parent.registerPrototype("rod", TestBean.class, new PropertyValues(m));
    m.put("name", "Albert");
    parent.registerPrototype("father", TestBean.class, new PropertyValues(m));
    parent.registerSingleton(StaticApplicationContext.APPLICATION_EVENT_MULTICASTER_BEAN_NAME, TestApplicationEventMulticaster.class, null);
    parent.refresh();
    parent.addApplicationListener(parentListener);
    parent.getStaticMessageSource().addMessage("code1", Locale.getDefault(), "message1");
    this.sac = new StaticApplicationContext(parent);
    sac.registerSingleton("beanThatListens", BeanThatListens.class, new PropertyValues());
    sac.registerSingleton("aca", ACATester.class, new PropertyValues());
    sac.registerPrototype("aca-prototype", ACATester.class, new PropertyValues());
    PropertiesBeanDefinitionReader reader = new PropertiesBeanDefinitionReader(sac.getBeanFactory());
    Resource resource = new ClassPathResource("testBeans.properties", getClass());
    reader.loadBeanDefinitions(new EncodedResource(resource, "ISO-8859-1"));
    sac.refresh();
    sac.addApplicationListener(listener);
    sac.getStaticMessageSource().addMessage("code2", Locale.getDefault(), "message2");
    return sac;
}
Also used : PropertyValues(cn.taketoday.beans.PropertyValues) HashMap(java.util.HashMap) PropertiesBeanDefinitionReader(cn.taketoday.beans.factory.support.PropertiesBeanDefinitionReader) Resource(cn.taketoday.core.io.Resource) EncodedResource(cn.taketoday.core.io.EncodedResource) ClassPathResource(cn.taketoday.core.io.ClassPathResource) ClassPathResource(cn.taketoday.core.io.ClassPathResource) EncodedResource(cn.taketoday.core.io.EncodedResource)

Aggregations

PropertyValues (cn.taketoday.beans.PropertyValues)2 PropertiesBeanDefinitionReader (cn.taketoday.beans.factory.support.PropertiesBeanDefinitionReader)2 ClassPathResource (cn.taketoday.core.io.ClassPathResource)2 EncodedResource (cn.taketoday.core.io.EncodedResource)2 Resource (cn.taketoday.core.io.Resource)2 HashMap (java.util.HashMap)2