2011-08-29 127 views
0

我想將systemProperties注入到JSF託管Bean(jsf 1.2)中。將Spring @Value systemProperties用於託管Bean

這可以做的唯一方法是如果我使用託管屬性或創建一個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> 

回答

0

JSF託管的豆可以被春天管理。你只需要配置<el-resolver>在特定的彈簧faces-config.xml中:

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

這既解決了Spring上下文中管理豆(當然,你在web.xml中需要一個ContextLoaderListener是白手起家春天,但我假設你有)。然後你可以在你的jsf bean中使用@Value,依賴注入等等。

唯一的區別是您將用@Controller @Scope("request")而不是xml來定義它們。

+0

這就是我的想法,我做了EL-RESOLVER定義,並通過ContextLoaderListener加載我的spring xml。我是否必須將@Controller註釋與@Value一起使用?現在我只需在faces-config xml中定義我的託管bean。 – haju

+0

對不起有關上限,編輯這件事情不會讓我做出改變,以降低那大聲笑 – haju

+0

是的,'@控制器'和'@價值'。在配置文件中沒有xml – Bozho

0

您可以註釋JSF豆與@Configurable,那麼你可以使用它像一個Spring bean。 (注意這需要使用AspectJ)

+0

當你說要求使用AspectJ時,你的意思只是Spring的jar嗎?AspectJ必須在類路徑或者一些configuratino上嗎? – haju

+0

我的意思是AspectJ編譯時編織 - 但我猜Bozho的答案我更好的解決方案 – Ralph