我有一堂课BaseResource.java
如下:
public class BaseResource{
protected UserManager userManager;
public void doSth(){
Object obj = userManager.returnObject(); //This is where exception is thrown
}
public UserManager getUserManager() {
return userManager;
}
public void setUserManager(UserManager userManager) {
this.userManager = userManager;
}
}
你可以看到二传手,对吧?这BaseResource
有一个孩子CustomerResurce.java
:
public class CommonResources extends BaseResource{
private UserManager userManager;
public void doSthElse(){
Object obj = doSth(); // Calling its parent's method
//Other stuff
}
public UserManager getUserManager() {
return userManager;
}
public void setUserManager(UserManager userManager) {
this.userManager = userManager;
}
}
当UserManager
孩子的班级中有并调用父母的方法时,JavaNullPointException
上升。但是当我删除
private UserManager usermanager;
(及其getter和setter)从孩子的班级开始,问题就解决了!这是为什么?
这是我的弹簧配置:
<bean id="baseResource" class="com.datx.web.resources.core.BaseResource"
scope="session" autowire="byName" />
<bean id="customerResources" class="com.datx.web.resources.core.CustomerResources"
scope="session" autowire="byName" />
<bean id="userManager" class="com.datx.usermanagement.manager.UserManager"
autowire="byName" scope="prototype"/>