Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring getActiveProfiles();始终为空_Spring_Environment Variables_Spring Profiles - Fatal编程技术网

Spring getActiveProfiles();始终为空

Spring getActiveProfiles();始终为空,spring,environment-variables,spring-profiles,Spring,Environment Variables,Spring Profiles,我在xhtml中有一个页面,我不想在生产环境中呈现这个页面,所以我用面板包装了页面上的所有元素 <p:panel id="main" rendered="#{swaggerBean.activeProfiles}" > 尝试进入页面后,第行出现空指针异常: String[] activeProfiles = environment.getActiveProfiles(); 我还尝试通过@ManagedProperty注入环境,但结果是一样的

我在xhtml中有一个页面,我不想在生产环境中呈现这个页面,所以我用面板包装了页面上的所有元素

<p:panel id="main" rendered="#{swaggerBean.activeProfiles}" >
尝试进入页面后,第行出现空指针异常:

String[] activeProfiles = environment.getActiveProfiles();
我还尝试通过@ManagedProperty注入环境,但结果是一样的

    @ManagedProperty(value="#{environment}")
    private Environment environment;
您知道如何避免@ManagedBean上的空指针吗?
我尝试了使用EnvironmentAware的解决方案,但仍然存在NPE,或者可能有更好的方法禁用我的生产页面?

用@Component而不是@ManagedBean注释SwaggerBean

    @ManagedProperty(value="#{environment}")
    private Environment environment;