Skip to content

Gyumeijie/ioc-containerx

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ioc-containerx

The ioc-containerx is a simple container for ioc, and use xml to configure beans. The following picture shows how it works.

Usage

  1. configurations file: beans.xml
<?xml version="1.0" encoding="UTF-8"?>

<beans>
    <bean id="me" class="com.github.gyumeijie.containerx.demo.Developer">
        <property name="name" value="Gyumeijie"/>
        <property name="location" value="Hangzhou, China"/>
    </bean>

    <bean id="myFriendOne" class="com.github.gyumeijie.containerx.demo.Developer">
        <property name="name" value="yebokang"/>
        <property name="location" value="Hangzhou, China"/>
    </bean>

    <bean id="myFriendTwo" class="com.github.gyumeijie.containerx.demo.Developer">
        <property name="name" value="yehengxuan"/>
        <property name="location" value="Hangzhou, China"/>
    </bean>
</beans>
  1. bean class demo: Developer.java
public class Developer {
  private String name;
  private String location;

  public String getName() {
    return name;
  }

  public void setName(String name) {
    this.name = name;
  }

  public String getLocation() {
    return location;
  }

  public void setLocation(String location) {
    this.location = location;
  }

  @Override
  public String toString() {
    return "Hi, my name is " + name + " and my current location is in" + location;
  }
}
  1. application: App.java
public class App {

  public static void main(String args[]) {
    BeanFactory beanFactory = new DefaultBeanFactory("beans.xml");

    Developer me = (Developer) beanFactory.getBean("me");
    System.out.println(me);

    Developer friendOne = (Developer) beanFactory.getBean("myFriendOne");
    System.out.println(friendOne);

    Developer friendTwo = (Developer) beanFactory.getBean("myFriendTwo");
    System.out.println(friendTwo);
  }
}

Related works

About

simple XML-based ioc container for java

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages