为什么在这种豆中使用NPE?
|
我有一个会话bean:
<managed-bean>
<managed-bean-name>mainMenuNavigationBean</managed-bean-name>
<managed-bean-class>com.cloud.common.jsf.core.beans.MainMenuNavigationBean</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
我将其注入到请求bean中:
<managed-bean>
<managed-bean-name>createAccountBean</managed-bean-name>
<managed-bean-class>com.cloud.common.jsf.account.CreateAccountBean</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
<managed-property>
<property-name>mainMenuNavigationBean</property-name>
<property-class>com.cloud.common.jsf.core.beans.MainMenuNavigationBean</property-class>
<value>#{mainMenuNavigationBean}</value>
</managed-property>
</managed-bean>
现在,我正在尝试在我的createAccountBean的@PostConstruct中使用一个setter,但我不明白为什么mainMenuNavigationBean在此处为null ...我希望在访问createAccountBean时如果它为null,则会自动创建它
@PostConstruct
public void init() {
userLoginVo = new UserLoginVo();
//NPE here
mainMenuNavigationBean.setExternalPage(true);
}
你能给我一个提示吗?我不明白自己在做什么错...
没有找到相关结果
已邀请:
1 个回复
浆错
并且,您需要确保接受者具有有效的属性和有效的设置方法。
注意设置器中的
,如果忽略该设置,则设置器无效。