ApplicationContext ctx = new FileSystemXmlApplicationContext("c:/beans.xml");ExampleBean eb = (ExampleBean)ctx.getBean("exampleBean");
String[] ctxs = new String[]{"ctx1.xml", "ctx2.xml"};ApplicationContext ctx = new FileSystemXmlApplicationContext(ctxs);
ApplicationContext parent = new ClassPathXmlApplicationContext("ctx1.xml");ApplicationContext ctx = new FileSystemXmlApplicationContext("ctx2.xml", parent);
Resource getResource(String location)
interface Resource {boolean exists();
boolean isOpen();
String getDescription();
File getFile() throws IOException;
InputStream getInputStream() throws IOException;
}
<property name="resourceProperty">
<value>example/image.gif</value>
</property>
String getMessage(String code, Object[] args, String default, Locale loc)
<bean id="messageSource" class="...ResourceBundleMessageSource">
<property name="basenames">
<value>messages,errors</value>
</property>
</bean>
public class MyListenerBean implements ApplicationListener {public void onApplicationEvent(ApplicationEvent e) {// process event
}
}
public class ExampleBean implements ApplicationContextAware {ApplicationContext ctx;
public void setApplicationContext(ApplicationContext ctx)
throws BeansException {this.ctx = ctx;
}
public void sendEvent() {ctx.publishEvent(new MyApplicationEvent(this));
}
}
public class MyPostProcessor implements BeanFactoryPostProcessor {void postProcessBeanFactory(ConfigurableListableBeanFactory bf) {DateFormat fmt = new SimpleDateFormat("d/M/yyyy");CustomDateEditor dateEditor = new CustomDateEditor(fmt, false);
bf.registerCustomEditor(java.util.Date.class, dateEditor);
}
}
<bean id="myPostProcessor" class="eg.MyPostProcessor"/>
<bean id="customEditorConfigurer" class="...CustomEditorConfigurer">
<property name="customEditors">
<map>
<entry key="java.util.Date">
<bean class="...CustomDateEditor">
<constructor-arg index="0">
<bean class="java.text.SimpleDateFormat">
<constructor-arg><value>d/M/yyyy</value></constructor-arg>
</bean>
</constructor-arg>
<constructor-arg index="1"><value>false</value></constructor-arg>
</bean>
</entry>
</map>
</property>
</bean>