将什么放入 applicationContext 和 faces-config?
What to put into applicationContext and faces-config?
我创建了一个 JSF 应用程序,但不确定应该将什么放入 faces-config?
我的一个 ManagedBean 如下所示:
@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
中定义了 <managed-beans>
,但我已经在 java class 中使用了 @ManagedBean
注释。这真的有必要吗?我的 jsf spring 设置正确吗?我还应该在 faces-config
中定义托管 bean 吗?
您在 faces-config 中配置的 SpringBeanFacesELResolver
的目的是为了让您可以使用 Spring beans 而不是旧式的 JSF 托管 beans 或 CDI 依赖注入.
从您的 ProfileBean
class 中删除 @ManagedBean
注释。您不需要它,因为您使用的是 Spring 而不是 JSF 的旧托管 beans 机制。
@ManagedBean
注释是旧版本 JSF 的残余;如果您使用的是较新版本的 JSF,请不要使用它。当前版本的 JSF 使用 CDI(用于依赖注入的标准 Java EE API),但您使用的是 Spring,因此您应该以 Spring 方式配置 bean(自从您在 Spring XML 配置中定义 ProfileBean
以来,您已经在做这些了。
我创建了一个 JSF 应用程序,但不确定应该将什么放入 faces-config?
我的一个 ManagedBean 如下所示:
@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
中定义了 <managed-beans>
,但我已经在 java class 中使用了 @ManagedBean
注释。这真的有必要吗?我的 jsf spring 设置正确吗?我还应该在 faces-config
中定义托管 bean 吗?
您在 faces-config 中配置的 SpringBeanFacesELResolver
的目的是为了让您可以使用 Spring beans 而不是旧式的 JSF 托管 beans 或 CDI 依赖注入.
从您的 ProfileBean
class 中删除 @ManagedBean
注释。您不需要它,因为您使用的是 Spring 而不是 JSF 的旧托管 beans 机制。
@ManagedBean
注释是旧版本 JSF 的残余;如果您使用的是较新版本的 JSF,请不要使用它。当前版本的 JSF 使用 CDI(用于依赖注入的标准 Java EE API),但您使用的是 Spring,因此您应该以 Spring 方式配置 bean(自从您在 Spring XML 配置中定义 ProfileBean
以来,您已经在做这些了。