【问题标题】:injecting springbean into jsf managed bean?将springbean注入jsf托管bean?
【发布时间】:2023-03-27 04:14:01
【问题描述】:

我将类监听器放在我的 WEB.xml 中

<listener>
<listener-class>org.springframework.web.context.request.
    RequestContextListener</listener-class> 
</listener>

在 facesconfig.xml 中

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

在 applicationcontext.xml 中

<context:component-scan base-package="com.test.jsf" />

和我在 jsf 中的 managedbean

package com.test.jsf;

@ManagedBean
@Controller
@Scope(value = "request")
public class page1_backing
{
 @Autowired
 private UserInfo ui;

 ...
 }

但显示警告以添加处理程序。然后我把

 <view-handler>com.sun.facelets.FaceletViewHandler</view-handler

但它并没有让我去smmothe。请帮助我完成这项任务。

【问题讨论】:

  • 不要使用 JSF 注释,而只是使用 spring 注释.. 全部交给 spring

标签: spring jsf


【解决方案1】:

不仅仅是 RequestContextListener。还要添加 ContextLoaderListener。

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<listener>
    <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>

并且只对托管bean使用@Component注解,

package com.test.jsf;

@Component
@Scope(value = "request")
public class page1_backing
{
    @Autowired
    private UserInfo ui;

    ...
}

它应该可以工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-01-27
    • 1970-01-01
    • 2014-07-01
    • 2015-03-11
    • 2013-01-23
    • 2013-07-28
    • 2013-05-08
    • 1970-01-01
    相关资源
    最近更新 更多