XmlBeanFactory Demo : XmlBeanFactory « Spring « Java

XmlBeanFactory Demo

File: context.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"

    <bean id="simple1" class="SoutSimpleBean">
        <property name="person" value="A"/>
        <property name="value" value="my value"/>


File: Main.java

import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource;

public class Main {
  public static void main(String[] args) throws Exception {
    XmlBeanFactory factory = new XmlBeanFactory(new ClassPathResource("context.xml"));


class SoutSimpleBean extends SimpleBeanSupport {
  private String person;

  public void setPerson(String person) {
    this.person = person;

  public String toString() {
    return String.format("%s : \"%s\"", this.person, getValue());

abstract class SimpleBeanSupport implements InitializingBean {
  private String value;

  public final void afterPropertiesSet() throws Exception {

  public final void setValue(String value) {
    this.value = value;

  protected final String getValue() {
    return this.value;


Spring-XmlBeanFactoryDemo.zip( 2,599 k)

Related examples in the same category

1.Create XmlBeanFactory from ClassPathResource
2.FactoryObject Integration
3.Spring factory method
4.BeanFactoryAware and BeanAware