我有一个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注入Environment,但结果是相同的
@ManagedProperty(value="#{environment}")
private Environment environment;
你知道如何在我的@ManagedBean上避免这个空指针吗?我尝试了Autowired Environment is null的EnvironmentAware解决方案,但仍然存在NPE,或者也许有更好的方法在生产环境中禁用我的页面?
发布于 2020-08-25 19:42:04
使用@Component而不是@ManagedBean注释SwaggerBean
https://stackoverflow.com/questions/63577853
复制相似问题