我已经成功地将JSF与Spring WebFlow& PrimeFaces,但@ManagedProperty注入在我的网络流程中始终为NULL ,但使用@Autowired注释注入工作。 我想知道为什么@ManagedProperty无效但@Autowired有效。
我的环境:Spring 3.2.1.RELEASE,JSF 2.2.4,PrimeFaces 3.0。
UserBean类:
@ManagedBean
public class UserBean implements Serializable {
@ManagedProperty(value="#{messageBean}")
private MessageBean messageBean;
public MessageBean getMessageBean() {
return messageBean;
}
public void setMessageBean(MessageBean messageBean) {
this.messageBean = messageBean;
}
}
MessageBean类:
@ManagedBean(name = "messageBean")
public class MessageBean implements Serializable {
public String getMessage(){
return "Hello, " + name;
}
}
面-config.xml中:
<application>
<el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver>
</application>
webflow.xml:
<!-- Executes flows: the central entry point into the Spring Web Flow system -->
<flow-executor id="flowExecutor">
<flow-execution-listeners>
<listener ref="facesContextListener"/>
</flow-execution-listeners>
</flow-executor>
<!-- The registry of executable flow definitions -->
<flow-registry id="flowRegistry" flow-builder-services="flowBuilderServices" base-path="/WEB-INF/flows">
<flow-location-pattern value="/**/flow.xml" />
<flow-location id="parent-flow" path="parent-flow.xml"/>
</flow-registry>
<!-- Configures the Spring Web Flow JSF integration -->
<faces:flow-builder-services id="flowBuilderServices" development="true" />
<!-- A listener to create and release a FacesContext -->
<beans:bean id="facesContextListener" class="org.springframework.faces.webflow.FlowFacesContextLifecycleListener"/>
我还有文件flow.xml和view.xhtml,因为我使用PrimeFaces将spring web flow与JSF集成在一起。
WEB-INF /流/ Ajax的JSF / flow.xml:
<var name="userBean" class="org.springframework.samples.webflow.ajax.UserBean" />
<var name="messageBean" class="org.springframework.samples.webflow.ajax.jsf.MessageBean" />
<view-state id="view">
<transition on="suggest" >
<evaluate expression="userBean.createEmailSuggestion(flowRequestContext)"
result="viewScope.emailSuggestion" />
</transition>
</view-state>
你知道为什么我的@ManagedProperty注射失败了吗?如果我用@Autowired替换@ManagedProperty,我可以看到该对象已创建,但@ManagedProperty始终为null。