Skip to content
Java编写的ioc工具
Java
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
.gitignore
CNAME
LICENSE
README.md
pom.xml

README.md

sunflower-ioc

这是一个基于注解的简易ioc工具, 为什么要重复造轮子呢, 只是为了好玩.😁

用法

在Class上使用@Bean标注一个对象需要容器管理;

在Field上使用@Resource标注依赖, 该field需要提供setter器.

示例

@Bean("jack")
public class Person {

    private String name = "jack";

    public String getName() {
        return name;
    }
}

@Bean("hi")
public class Hi {
    @Resource("jack")
    private Person person;

    /**
     * Say Hello
     */
    public void sayHello() {

        System.out.println("Hello " + person.getName());

    }

    public void setPerson(Person person) {
        this.person = person;
    }
}

注入示例

Set<Class<?>> classes = new Scanner().scanPackage("com.mlongbo.sunflower.ioc.bean");

BeanContext.me().init(classes);

Hi hi = (Hi) BeanContext.me().getBean("hi");
hi.sayHello();
You can’t perform that action at this time.