国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費(fèi)電子書(shū)等14項(xiàng)超值服

開(kāi)通VIP
S2SH+proxool JNDI 數(shù)據(jù)源
Struts2 Spring2.5 Hibernate3.2 proxool9.1 tomcat6.18配置整合
網(wǎng)上很多朋友講到了hibernate怎么用proxool
單獨(dú)的怎么配置proxool,卻很少把struts2和spring2還有hibernate整合起來(lái)的.花了一天的時(shí)候,才把配置整成功,分享出來(lái)給大家,希望可以少走彎路吧.
這里和大家講一下,為什么要用tomcat來(lái)啟動(dòng)數(shù)據(jù)庫(kù)連接池.除了資源控制一塊,還有一個(gè)很大的原因是因?yàn)閟truts2要求spring的加載方式為<listener>
而spring會(huì)整合hibernate,在實(shí)例化的時(shí)候,會(huì)去加載proxool數(shù)據(jù)鏈接池.
因?yàn)閜roxool的加載方式是通過(guò)<servlet>方式來(lái)的,加載順序在<listener>之后,也就是spring的后面加載.這樣加載會(huì)不成功.
所以proxool的加載只能是在spring之前加載.網(wǎng)上有一個(gè)網(wǎng)友把proxool的加載方式改成了 <listener> 放在spring之前加載,這樣太麻煩了,還要改源碼.
于是這個(gè)方式成本就最低了.
當(dāng)然,也有網(wǎng)友提到
寫(xiě)道
直接在application.xml配上
<prop key="hibernate.proxool.xml">proxool.xml</prop>
以上引用,我配置后,并沒(méi)有作用.估計(jì)那位網(wǎng)友使用的版本和我的不同吧.反正我試了半天是沒(méi)有成功.
tomcat/conf/context.xml 配置proxool.
加在
Xml代碼 
</Context>
元素的前面 proxool的配置元素,就不多講了,網(wǎng)上有很多詳細(xì)的介紹.這里給大家一個(gè)鏈接:http://wallimn.javaeye.com/blog/486550
Xml代碼 
<Resource name="jdbc/mysql"
auth="Container"
type="javax.sql.DataSource"
factory="org.logicalcobwebs.proxool.ProxoolDataSource"
proxool.alias="DBPool"
user="root"
password="root"
delegateProperties="foo=bar"
proxool.jndi-name="mysqljndi"
proxool.driver-url="jdbc:mysql://127.0.0.1:3306/webgame?characterEncoding=utf-8"
proxool.driver-class="com.mysql.jdbc.Driver"
proxool.house-keeping-sleep-time="40000"
proxool.house-keeping-test-sql="SELECT ''"
proxool.maximum-connection-count="100"
proxool.minimum-connection-count="20"
proxool.maximum-connection-lifetime="18000000"
proxool.simultaneous-build-throttle="20"
proxool.recently-started-threshold="40000"
proxool.overload-without-refusal-lifetime="50000"
proxool.maximum-active-time="60000"
proxool.verbose="true"
proxool.trace="true"
proxool.fatal-sql-exception="Fatal error"
proxool.prototype-count="2"
proxool.statistics-log-level="ERROR
/>
現(xiàn)在就不需要單獨(dú)的來(lái)配置proxool.properies 和proxool.xml了.
記得把proxool-0.9.1.jar和proxool-cglib.jar包復(fù)制到tomcat/lib文件夾下,否則會(huì)報(bào)找不到
Xml代碼 
org.logicalcobwebs.proxool.ProxoolDataSource
錯(cuò)誤.把包放到自己項(xiàng)目下的話,會(huì)報(bào)這個(gè)錯(cuò),但是也可以運(yùn)行的.
接下來(lái)是配置web.xml
Xml代碼 
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 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-app_2_5.xsd">
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>classpath:log4j.properties</param-value>
</context-param>
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.FilterDispatcher
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- 加載數(shù)據(jù)連接池及監(jiān)控?cái)?shù)據(jù)連接池功能 -->
<!-- 由于已經(jīng)通過(guò)tomcat的jndi來(lái)加載了數(shù)據(jù)連接,所以這樣里以不需要了
<servlet>
<servlet-name>ServletConfigurator</servlet-name>
<servlet-class>
org.logicalcobwebs.proxool.configuration.ServletConfigurator
</servlet-class>
<init-param>
<param-name>propertyFile</param-name>
<param-value>
WEB-INF\classes\proxool.properties
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
-->
<servlet>
<servlet-name>Admin</servlet-name>
<servlet-class>
org.logicalcobwebs.proxool.admin.servlet.AdminServlet
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Admin</servlet-name>
<url-pattern>/proxool.admin</url-pattern>
</servlet-mapping>
<!-- 加載spring文件 -->
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
</web-app>
applicationContext.xml
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" xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">
<import resource="classes/xml/spring/games.xml" />
<import resource="classes/xml/spring/blcx.xml" />
<!-- 使用tomcat jndi數(shù)據(jù)連接池 ,這里項(xiàng)目中的servlet就不用配置啟動(dòng)連接池了-->
<bean id="dataSource"
class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName">
<value>java:comp/env/jdbc/mysql</value>
</property>
</bean>
<!-- Hibernate設(shè)置 -->
<!-- 會(huì)話工廠設(shè)置,讀取Hibernate數(shù)據(jù)庫(kù)配置信息 -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
<prop key="hibernate.proxool.existing_pool">true</prop>
<prop key="hibernate.format.sql">true</prop>
<prop key="hibernate.show.sql">true</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>com/webgame/account/form/WebgameAccount.hbm.xml</value>
<value>com/webgame/account/form/WebgameAccountIndex.hbm.xml</value>
<value>com/webgame/pay/form/WebgameAccountFinancingLog.hbm.xml</value>
<value>com/webgame/pay/form/WebgameCategoriesRate.hbm.xml</value>
</list>
</property>
</bean>
<!-- Spring設(shè)置 -->
<!-- 會(huì)話模板 -->
<bean id="hibernateTemplate"
class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<!-- 事務(wù)管理器 -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>
</bean>
<!-- 配置事務(wù)攔截器-->
<bean id="transactionInterceptor"
class="org.springframework.transaction.interceptor.TransactionInterceptor">
<!-- 事務(wù)攔截器bean 需要依賴(lài)注入一個(gè)事務(wù)管理器-->
<property name="transactionManager">
<ref local="transactionManager" />
</property>
<property name="transactionAttributes">
<!-- 下面定義事務(wù)傳播屬性-->
<props>
<prop key="save">PROPAGATION_REQUIRED</prop>
<prop key="dele*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
<!--注入到dao類(lèi)里-->
<bean id="accountIndexDao" class="com.webgame.account.dao.impl.AccountIndexDao"
p:hibernateTemplate-ref="hibernateTemplate"
/>
</beans>
以上配置基本解決了啟動(dòng)方面的問(wèn)題.
使用:
Java代碼 
package com.webgame.account.dao.impl;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.apache.log4j.Logger;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import com.webgame.account.dao.interfaces.IAccountDao;
import com.webgame.account.form.AccountBean;
/**
* 類(lèi)實(shí)現(xiàn)全局所有種類(lèi)游戲的賬號(hào)信息數(shù)據(jù)操作類(lèi)
*
*
*/
public class AccountDao extends HibernateDaoSupport implements IAccountDao{
private static final Logger logger = Logger.getLogger(AccountDao.class);
/*
* (non-Javadoc)
*
* @see com.webgame.accout.dao.interfaces.IAccountDao#getAccountBean(java.lang.String,
*      java.lang.String[])
*/
public AccountBean getAccountBean(String sql) throws SQLException {
AccountBean form = new AccountBean();
List list = getHibernateTemplate().find(sql);
if (list.size() == 1)
form = (AccountBean) list.get(0);
return form;
}
/*
* (non-Javadoc)
*
* @see com.webgame.account.dao.interfaces.IAccountDao#getAccountCount(java.lang.String)
*/
@Override
public int getAccountCount(String sql) throws SQLException {
int reInt = 0;
List list = getHibernateTemplate().find(sql);
reInt = list.size();
return reInt;
}
/*
* (non-Javadoc)
*
* @see com.webgame.account.dao.interfaces.IAccountDao#getAccountList(java.lang.String)
*/
@SuppressWarnings("unchecked")
@Override
public List<AccountBean> getAccountList(String sql) throws SQLException {
List<AccountBean> list = new ArrayList<AccountBean>();
list = getHibernateTemplate().find(sql);
return list;
}
@Override
public boolean checkAccountExist(final String property,final String value) {
return (Boolean)getHibernateTemplate().execute(new HibernateCallback(){
@SuppressWarnings("unchecked")
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
List<AccountBean> list = session.createCriteria(AccountBean.class).add(Restrictions.eq(property, value)).list();
if(list != null && list.size() > 0 )
return true;
else return false;
}
});
}
@Override
public AccountBean getAccountBeanByName(final String accountName) {
return (AccountBean)getHibernateTemplate().execute(new HibernateCallback(){
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
return session.createCriteria(AccountBean.class).add(
Restrictions.eq("accountName", accountName))
.setMaxResults(1).uniqueResult();
}
});
}
public boolean saveAccount(AccountBean bean) throws SQLException {
bean.setInTime(new Date());
getHibernateTemplate().save(bean);
return true;
}
}
本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶(hù)發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)。
打開(kāi)APP,閱讀全文并永久保存 查看更多類(lèi)似文章
猜你喜歡
類(lèi)似文章
proxool 簡(jiǎn)單使用
SSH實(shí)現(xiàn)的增刪改查實(shí)例
spring and hibernate,spring and tapestry整合篇
各種連接池的比較
基于Maven的Spring + Spring MVC + Mybatis的環(huán)境搭建 | AmazingHarry
Proxool連接池相關(guān)介紹
更多類(lèi)似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長(zhǎng)圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服