将Spring @Value systemProperties用于Managed Bean

时间:2011-08-29 18:08:53

标签: spring jsf

我想将systemProperties注入JSF Managed Bean(jsf 1.2)。

这可以做到的唯一方法是,如果我使用托管属性或创建一个systemProperties bean并将其注入我想要的托管bean,对吗?我不能像@Value那样使用;为了让我这样做,它必须是一个春天豆。

#{systemProperties['databaseName']}

#{systemProperties.databaseName}

管理财产

    <managed-bean>
    <managed-bean-name>fooUI</managed-bean-name>
    <managed-bean-class>test.foo</managed-bean-class>
    <managed-bean-scope>session</managed-bean-scope>
    <managed-property>
        <property-name>systemPropertyExample</property-name>
        <value>#{systemProperties['systemPropertyExample']}</value>
    </managed-property>  
</managed-bean>  

2 个答案:

答案 0 :(得分:0)

您可以使用@Configurable注释JSF Bean,然后您可以像使用spring bean一样使用它。 (注意这需要使用AspectJ)

答案 1 :(得分:0)

JSF托管bean 可以进行弹簧管理。您只需在faces-config.xml中配置特定于spring的<el-resolver>

<el-resolver>
     org.springframework.web.jsf.el.SpringBeanFacesELResolver
</el-resolver> 

它将在spring上下文中解析托管bean(当然,你需要在web.xml中使用ContextLoaderListener来引导Spring,但我认为你已经有了。{然后你可以在你的jsf bean中使用@Value,依赖注入等。

唯一的区别是你将使用@Controller @Scope("request")而不是xml来定义它们。

相关问题