Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

执行报空指针异常,PojoBean1 pojoBean1 = appContext.getInstance(PojoBean1.class); #92

Open
GitHub-19 opened this issue Mar 22, 2021 · 0 comments

Comments

@GitHub-19
Copy link

import net.hasor.core.AppContext;
import net.hasor.core.Hasor;
import net.hasor.core.aop.SimplePropertyDelegate;
import net.hasor.utils.BeanUtils;
import org.junit.Test;

/**

public class PropertyDelegateTest {
@test
public void test(){
// 注册两个 Bean 并且共享同一个 name 属性。
AppContext appContext = Hasor.create().build(apiBinder -> {
SimplePropertyDelegate delegate = new SimplePropertyDelegate("helloWord");
apiBinder.bindType(PojoBean1.class).dynamicProperty("name", String.class, delegate);
apiBinder.bindType(PojoBean2.class).dynamicProperty("name", String.class, delegate);
});
// 创建两个 Bean
PojoBean1 pojoBean1 = appContext.getInstance(PojoBean1.class);
PojoBean2 pojoBean2 = appContext.getInstance(PojoBean2.class);
//
assert BeanUtils.readProperty(pojoBean1, "name").equals("helloWord");
assert BeanUtils.readProperty(pojoBean2, "name").equals("helloWord");
BeanUtils.writeProperty(pojoBean1, "name", "newValue");
assert BeanUtils.readProperty(pojoBean1, "name").equals("newValue");
assert BeanUtils.readProperty(pojoBean2, "name").equals("newValue");
}
}

class PojoBean1{
private String uuid;

public String getUuid() {
    return uuid;
}

public void setUuid(String uuid) {
    this.uuid = uuid;
}

}

class PojoBean2{
private String uuid;

public String getUuid() {
    return uuid;
}

public void setUuid(String uuid) {
    this.uuid = uuid;
}

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant