充实博客为主,粗略讲解这是JSH集成(JSF.Spring.Hibernate) 2008-11-22,
开发环境:MyEclipse6.0.1+JDK1.6+Oracle9i
首先添加JSF兼容,选myfaces插件.依照JSF.Spring.Hibernate流程添加兼容,会更容易点,这点会SSH集成的都不会有什么问题
接着,我们看到web.xml
添加Spring控制器(上下文对象)
<servlet>
<servlet-name>context</servlet-name>
<servlet-class>
org.springframework.web.context.ContextLoaderServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/classes/applicationContext.xml
</param-value>
</context-param>
接着,我们看到faces-config.xml
添加 告诉系统配置Manager Bean的时候去根据下面的去寻找spring.xml中配置的bean信息
<application>
<variable-resolver>
org.springframework.web.jsf.DelegatingVariableResolver
</variable-resolver>
</application>
到这里,配置就差不多完成了,但是又牵涉到Manager Bean是交给Spring管理,还是JSF管理,这里,我演示两种解决方案
一:交由Spring管理
更改applicationContext.xml的beans开头标签,就是一长串的网址,更改为Spring2.0版本
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
更改web.xml的myfaces监听器,设置成
<listener>
<listener-class>
org.springframework.web.context.request.RequestContextListener
</listener-class>
</listener>
最后增加一个bean的属性,例拥有request,session对象
<bean id="show" class="com.zgz008.web.ShowListBean" scope="request" />
结束
二:交由JSF管理
在faces-config.xml里作配置
<managed-bean>
<managed-bean-name>show</managed-bean-name>
<managed-bean-class>
com.zgz008.web.ShowListBean
</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
<managed-property>
<property-name>showService</property-name>
<value>#{showService}</value><!--#{}代表往application.xml里找id号,作依赖注入 -->
</managed-property>
</managed-bean>
附带一个Demo
必须要有Oracle.更改applicationContext(datasource)配置,测试数据只有10,20,30