JSF+Spring+Hibernate 配置

这几天开始用jsf+spring+hibernate.以前没有配置过jsf,所以在网上找了很多问题,也花了不少时间。
碰到的问题比较多,最终配置是这样的。

晕,只能上传三张照片
还是上传个word大家下载去看吧。
最主要的问题是JSF和SPRING的结合,我用的是SPRING手册极力推荐的方法。
使用DelegatingVariableResolver,这个用起来觉得还是比较干净的。
faces-config.xml的配置文件如下:

<?xml version='1.0' encoding='UTF-8'?>

<faces-config xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd"
version="1.2">

<application>
<variable-resolver>org.springframework.web.jsf.DelegatingVariableResolver</variable-resolver>
<locale-config>
<default-locale>zh_CN</default-locale>
<supported-locale>en</supported-locale>
<supported-locale>es</supported-locale>
</locale-config>

</application>

<navigation-rule>
<from-view-id>main</from-view-id>
</navigation-rule>

<managed-bean>
<managed-bean-name>product</managed-bean-name>
<managed-bean-class>com.geedao.righterp.web.page.MainBacking</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
<managed-property>
<property-name>productService</property-name>
<value>#{productService}</value>
</managed-property>

</managed-bean>
</faces-config>

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.5" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

<context-param>
<param-name>contextConfigLocaition</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<context-param>
<param-name>javax.faces.CONFIG_FILES</param-name>
<param-value>/WEB-INF/faces-config.xml</param-value>
</context-param>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>0</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>

proxool.xml

<?xml version="1.0" encoding="UTF-8"?>
<!-- the proxool configuration can be embedded within your own application's.
Anything outside the "proxool" tag is ignored. -->

<proxool>
<alias>erp</alias>
<driver-url>jdbc:mysql://localhost:3306/数据库名称</driver-url>
<driver-class>com.mysql.jdbc.Driver</driver-class>
<driver-properties>
<property name="user" value="用户名" />
<property name="password" value="密码" />
</driver-properties>
<minimum-connection-count>2</minimum-connection-count>
<maximum-connection-count>20</maximum-connection-count>
<maximum-connection-lifetime>180000</maximum-connection-lifetime> <!-- 5 hours -->
<house-keeping-test-sql>values(current TimeStamp)</house-keeping-test-sql>
<statistics>1m,15m,1d</statistics>
<statistics-log-level>INFO</statistics-log-level>
<fatal-sql-exception>Connection is closed,SQLSTATE=08003,Error opening socket. SQLSTATE=08S01,SQLSTATE=08S01</fatal-sql-exception>
<fatal-sql-exception-wrapper-class>org.logicalcobwebs.proxool.FatalRuntimeException</fatal-sql-exception-wrapper-class>
<verbose>false</verbose>
</proxool>

applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">

<bean id="SessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.cglib.use_reflection_optimizer">true</prop>
<prop key="hibernate.proxool.xml">proxool.xml</prop>
<prop key="hibernate.proxool.pool_alias">erp</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>com/geedao/righterp/domain/Product.hbm.xml</value>
<value>com/geedao/righterp/domain/User.hbm.xml</value>
</list>
</property>
</bean>
<bean id="productDAO" class="com.geedao.righterp.dao.hibernate.ProductDAO">
<property name="sessionFactory">
<ref bean="SessionFactory" />
</property>
</bean>
<bean id="userDAO" class="com.geedao.righterp.dao.hibernate.UserDAO">
<property name="sessionFactory">
<ref bean="SessionFactory" />
</property>
</bean>
<bean id="productService" class="com.geedao.righterp.service.method.ProductServiceMethod">
<property name="productDAO">
<ref bean="productDAO" />
</property>
</bean>
</beans>


public class MainBacking {

private int id;
private String name;
private User user;
private ProductService productService;
public List getProductList(){

//ApplicationContext ctx = FacesContextUtils.getWebApplicationContext(FacesContext.getCurrentInstance());
return productService.getList();
}

public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public ProductService getProductService() {
return productService;
}
public void setProductService(ProductService productService) {
this.productService = productService;
}

}

[color=red]加入richfaces后的配置也贴上来,其实richfaces自带的用户手册里面有的。我用的是3.2的,目前没有出现什么问题。[/color]

<display-name>a4jEchoText</display-name>
<context-param>
<param-name>org.richfaces.SKIN</param-name>
<param-value>blueSky</param-value>
</context-param>
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>server</param-value>
</context-param>
<filter>
<display-name>RichFaces Filter</display-name>
<filter-name>richfaces</filter-name>
<filter-class>org.ajax4jsf.Filter</filter-class>
</filter>
<filter-mapping>
<filter-name>richfaces</filter-name>
<servlet-name>Faces Servlet</servlet-name>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
<dispatcher>INCLUDE</dispatcher>
</filter-mapping>
<listener>
<listener-class>
com.sun.faces.config.ConfigureListener
</listener-class>
</listener>

把这一段加到web.xml里就可以了。


[url=http://www.hzzlprint.com]杭州印刷[/url]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值