问题描述
我在xhtml中有页面,我不想在生产中呈现此页面,所以我用面板包裹了页面上的所有元素
<p:panel id="main" rendered="#{swaggerBean.activeProfiles}" >
SwaggerBean.class:
@ManagedBean
@ViewScoped
@Data
public class SwaggerBean{
@Autowired
Environment environment;
public boolean getActiveProfiles() {
String[] activeProfiles = environment.getActiveProfiles();
for (String activeProfile : activeProfiles) {
if (activeProfile.contains("prod"))
return true;
}
return false;
}
}
尝试进入页面后,在行上出现空指针异常:
String[] activeProfiles = environment.getActiveProfiles();
我也尝试通过@ManagedProperty注入环境,但结果相同
@ManagedProperty(value="#{environment}")
private Environment environment;
您知道如何避免在@ManagedBean上使用此空指针吗? 我尝试使用Autowired Environment is null中的EnvironmentAware解决方案,但是仍然有NPE,或者也许有更好的方法来禁用我的生产页面?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)