我在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中的EnvironmentAware解决方案为null,但是仍然存在NPE,或者也许有更好的方法来禁用生产页面?
用@Component而不是@ManagedBean注释SwaggerBean
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句