我的spring的配置文件:
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" destroy-method="close">
<property name="location">
<value>classpath:sqlresource.properties</value>
</property>
</bean>
<!--
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="com.mysql.jdbc.Driver" />
<property name="jdbcUrl" value="${database.url}" />
<property name="user" value="${database.username}" />
<property name="password" value="${database.password}" />
<property name="autoCommitOnClose" value="false"/>
<property name="checkoutTimeout" value="5000"/>
<property name="initialPoolSize" value="5"/>
<property name="minPoolSize" value="5"/>
<property name="maxPoolSize" value="40"/>
<property name="maxIdleTime" value="60"/>
<property name="acquireIncrement" value="5"/>
<property name="idleConnectionTestPeriod" value="60" />
<property name="testConnectionOnCheckin" value="true" />
<property name="testConnectionOnCheckout" value="true"/>
<property name="maxIdleTimeExcessConnections" value="1800"/>
<property name="preferredTestQuery" value="select * from userinfo"/>
</bean>
-->
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource"
abstract= "false " singleton= "true "
lazy-init= "default " autowire= "default "
dependency-check= "default ">
<property name="driverClassName">
<value>${database.driverclassname}</value>
</property>
<property name="url">
<value>${database.url}</value>
</property>
<property name="username">
<value>${database.username}</value>
</property>
<property name="password">
<value>${database.password}</value>
</property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref local="dataSource" />
</property>
<property name="mappingResources">
<list>
<value>
cn/bozhong/apps/iptv/domain/Propinfo.hbm.xml
</value>
<value>cn/bozhong/apps/iptv/domain/Userfriend.hbm.xml</value>
<value>
cn/bozhong/apps/iptv/domain/Styleinfo.hbm.xml
</value>
<value>
cn/bozhong/apps/iptv/domain/Userprop.hbm.xml
</value>
<value>
cn/bozhong/apps/iptv/domain/Userinfo.hbm.xml
</value>
<value>cn/bozhong/apps/iptv/domain/Gameinfo.hbm.xml</value>
<value>cn/bozhong/apps/iptv/domain/Userstyle.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean> <bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>
</bean> <bean id="baseTxProxy" abstract="true"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager">
<ref bean="transactionManager" />
</property> <property name="transactionAttributes">
<props>
<prop key="*">PROPAGATION_REQUIRED</prop>
<prop key="save*">PROPAGATION_REQUIRED</prop>
<prop key="delete*">PROPAGATION_REQUIRED</prop>
<prop key="update*">PROPAGATION_REQUIRED</prop>
<prop key="select*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
<!-- Propinfo -->
<bean id="propinfoDao"
class="cn.bozhong.apps.iptv.service.dao.hibernate.PropinfoDao"
autowire="byName">
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>
</bean>
<bean id="propinfoService"
class="cn.bozhong.apps.iptv.service.spring.PropinfoService"
singleton="true" autowire="byName">
<property name="dao">
<ref local="propinfoDao" />
</property>
</bean>
<bean id="propinfoServiceProxy" parent="baseTxProxy">
<property name="target">
<ref local="propinfoService" />
</property>
</bean>
</beans>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" destroy-method="close">
<property name="location">
<value>classpath:sqlresource.properties</value>
</property>
</bean>
<!--
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="com.mysql.jdbc.Driver" />
<property name="jdbcUrl" value="${database.url}" />
<property name="user" value="${database.username}" />
<property name="password" value="${database.password}" />
<property name="autoCommitOnClose" value="false"/>
<property name="checkoutTimeout" value="5000"/>
<property name="initialPoolSize" value="5"/>
<property name="minPoolSize" value="5"/>
<property name="maxPoolSize" value="40"/>
<property name="maxIdleTime" value="60"/>
<property name="acquireIncrement" value="5"/>
<property name="idleConnectionTestPeriod" value="60" />
<property name="testConnectionOnCheckin" value="true" />
<property name="testConnectionOnCheckout" value="true"/>
<property name="maxIdleTimeExcessConnections" value="1800"/>
<property name="preferredTestQuery" value="select * from userinfo"/>
</bean>
-->
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource"
abstract= "false " singleton= "true "
lazy-init= "default " autowire= "default "
dependency-check= "default ">
<property name="driverClassName">
<value>${database.driverclassname}</value>
</property>
<property name="url">
<value>${database.url}</value>
</property>
<property name="username">
<value>${database.username}</value>
</property>
<property name="password">
<value>${database.password}</value>
</property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref local="dataSource" />
</property>
<property name="mappingResources">
<list>
<value>
cn/bozhong/apps/iptv/domain/Propinfo.hbm.xml
</value>
<value>cn/bozhong/apps/iptv/domain/Userfriend.hbm.xml</value>
<value>
cn/bozhong/apps/iptv/domain/Styleinfo.hbm.xml
</value>
<value>
cn/bozhong/apps/iptv/domain/Userprop.hbm.xml
</value>
<value>
cn/bozhong/apps/iptv/domain/Userinfo.hbm.xml
</value>
<value>cn/bozhong/apps/iptv/domain/Gameinfo.hbm.xml</value>
<value>cn/bozhong/apps/iptv/domain/Userstyle.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean> <bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>
</bean> <bean id="baseTxProxy" abstract="true"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager">
<ref bean="transactionManager" />
</property> <property name="transactionAttributes">
<props>
<prop key="*">PROPAGATION_REQUIRED</prop>
<prop key="save*">PROPAGATION_REQUIRED</prop>
<prop key="delete*">PROPAGATION_REQUIRED</prop>
<prop key="update*">PROPAGATION_REQUIRED</prop>
<prop key="select*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
<!-- Propinfo -->
<bean id="propinfoDao"
class="cn.bozhong.apps.iptv.service.dao.hibernate.PropinfoDao"
autowire="byName">
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>
</bean>
<bean id="propinfoService"
class="cn.bozhong.apps.iptv.service.spring.PropinfoService"
singleton="true" autowire="byName">
<property name="dao">
<ref local="propinfoDao" />
</property>
</bean>
<bean id="propinfoServiceProxy" parent="baseTxProxy">
<property name="target">
<ref local="propinfoService" />
</property>
</bean>
</beans>
解决方案 »
- 一个web service project可以提供几个服务?还有在xfire里service.xml如何配置?
- java导出pdf报表
- httpclient 登陆163问题
- 大家都来说说mysql数据库中文乱码这么解决的
- webservice 服务端如何获得客户端的ip地址?
- 请教个JDBC方式从MS SQL Server取smalldatetime和money数据类型问题,以及能否使用hibernate中实现同样功能?
- Struts标签Html:link中的page href action有什么区别?
- Jotm类包发布到WEBLOGIC引发类冲突(八百里加急)
- MSSQL驱动程序问题-急
- 在struts框架钟,formbean 如何保存信息,现在的问题是在action中form不为空,可是form的方法取的值为null
- 大家看下这个项目可否用Hibernate或者是Ibatis?
- JAVA配置问题哪位朋友帮忙看看(Rmi)
public List getList(final String hql, final int pageNo, final int pageSize) {
return this.getHibernateTemplate().executeFind(new HibernateCallback(){
public Object doInHibernate(Session session) throws HibernateException, SQLException {
Query query=session.createQuery(hql);
query.setFirstResult((pageNo-1)*pageSize); //hibernate分页的精髓 呵呵
query.setMaxResults(pageSize);
session.close();
return query.list();
}
});
}
数据库的连接问题
你的操作后,数据库连接没关。
public List getList(final String hql, final int pageNo, final int pageSize) {
return this.getHibernateTemplate().executeFind(new HibernateCallback(){
public Object doInHibernate(Session session) throws HibernateException, SQLException {
Query query=session.createQuery(hql);
query.setFirstResult((pageNo-1)*pageSize); //hibernate分页的精髓 呵呵
query.setMaxResults(pageSize);
session.close();
return query.list();
}
});
}