我创建了一个JSF应用程序,我不确定我应该把什么放到faces-config中?
我的ManagedBeans之一看起来如下所示:
@ManagedBean(name = "ProfileBean")
@ViewScoped
public class ProfileBean implements Serializable我的应用上下文
<context:annotation-config />
<bean class="org.springframework.context.annotation.CommonAnnotationBeanPostProcessor" />
<bean id="QuestionDao" class="code.elephant.dao.QuestionDao"></bean>
<bean id="QuestionService" class="code.elephant.service.QuestionService">
<constructor-arg ref="QuestionDao"/>
</bean>
<bean id="QuestionBean" class="controller.QuestionBean">
<constructor-arg ref="QuestionService"/>
</bean>
<bean id="UserDao" class="code.elephant.dao.UserDao"></bean>
<bean id="UserService" class="code.elephant.service.UserService">
<constructor-arg ref="UserDao"/>
</bean>
<bean id="LoginBean" class="controller.LoginBean">
<constructor-arg ref="UserService"/>
</bean>
<bean id="ProfileBean" class="controller.ProfileBean">
<constructor-arg ref="UserService" />
<property name="_LoginBean" ref="LoginBean"></property>
</bean>我的脸-配置
<application>
<el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver>
</application>我看到了一些在java-faces.config中定义@ManagedBean的例子,但是我已经在java类中使用了@ManagedBean注释。这有必要吗?我和jsf弹簧的安排对吗?我是否也应该在faces-config中定义托管bean?
发布于 2017-04-21 06:40:35
您在faces中配置的SpringBeanFacesELResolver的目的是使它能够使用Spring,而不是旧式的JSF托管bean或CDI依赖项注入。
从@ManagedBean类中删除ProfileBean注释。您不需要它,因为您正在使用Spring,而不是JSF的旧托管bean机制。
@ManagedBean注释是JSF旧版本遗留下来的;如果您使用的是较新版本的JSF,则不要使用它。当前版本的JSF使用CDI (用于依赖项注入的标准Java ),但您使用的是Spring,因此您应该使用Spring方式配置bean(自从您在Spring中定义了ProfileBean之后,就已经这样做了)。
https://stackoverflow.com/questions/43535495
复制相似问题