问题描述
|
问题描述:尚未实例化我定义为JSF支持bean的托管属性的注入Spring bean。当我取回Managed-Bean时,它总是空值。
我整天都在为此奋斗,似乎JSF Managed Bean不会从Spring读取applicationContext。我可以通过在备用Bean中使用FacesContext来手动拉出Bean,它会找到该Bean,但是当我尝试通过FacesConfig注入它时,它总是空值。我在整合步骤的下方列出了步骤。有什么建议么?
组态
冰面1.85
JSF 1.2(通过ice face servlet)
春季3.0
Websphere 7.5(我认为是eclipse 3.5)
Web.xml配置更改
Spring Context Loader侦听器
<listener>
<display-name>SpringListener</display-name>
<icon>
<small-icon>small.gif</small-icon>
<large-icon>large.gif</large-icon>
</icon>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
上下文配置
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/SpringConfig/SpringHelloWorld.xml
</param-value>
</context-param>
FacesContext更改
变量解析器-AKA The glue
<application><variable-resolver>org.springframework.web.jsf.DelegatingVariableResolver</variable-resolver></application>
托管豆
<managed-bean>
<managed-bean-name>testData</managed-bean-name>
<managed-bean-class>src.test.TestData</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
<managed-property>
<property-name>spring3HelloWorldBean</property-name>
<value>#{spring3HelloWorldBean}</value>
</managed-property>
</managed-bean>
Spring.xml配置
<bean id=\"spring3HelloWorldBean\" class=\"src.test.Spring3HelloWorld\" />
提前致谢
解决方法
首先,我认为这是在1.1之后的所有JSF版本中不赞成使用DelegatingVariableResolver的问题,并且您正在使用1.2,因此请使用以下配置。
<application>
<el-resolver>
org.springframework.web.jsf.el.SpringBeanFacesELResolver
</el-resolver>
</application>
希望能帮助到你。
, 除了使用ѭ6之外,您还可以通过使用注释从spring中受益更多。因此,不用在xml中定义托管bean,只需执行以下操作:
@Controller
public class FooBean {
@Inject
private SpringService service;
....
}