(绝对有效)sqlserver2000链接proxool连接池,终于配置出spring整合struts,hibernate annotation(pool数据池,sqlserver2000数据库)

(绝对有效)sqlserver2000链接proxool连接池,终于配置出spring整合struts,hibernate annotation(pool数据池,sqlserver2000数据库),第1张

概述首先proxool.xml(需要proxool-0.9.1.jar,proxool-cglib.jar和三个sqlserver包) <?xml version="1.0" encoding="UTF-8"?><something-else-entirely> <proxool> <alias>pool</alias> <driver-url>jdbc:microsoft:sq

首先proxool.xml(需要proxool-0.9.1.jar,proxool-cglib.jar和三个sqlserver包)

<?xml version="1.0" enCoding="UTF-8"?><something-else-entirely>  <proxool>    <alias>pool</alias>    <driver-url>jdbc:microsoft:sqlserver://localhost:1433;databasename=tour</driver-url>    <driver-class>com.microsoft.jdbc.sqlserver.sqlServerDriver</driver-class>    <driver-propertIEs>      <property name="user" value="sa"/>      <property name="password" value="sa"/>    </driver-propertIEs><house-keePing-sleep-time>90000</house-keePing-sleep-time><maximum-new-connections>20</maximum-new-connections><prototype-count>5</prototype-count><maximum-connection-count>100</maximum-connection-count> <check-valID-connection-sql>select * from t_user</check-valID-connection-sql><minimum-connection-count>10</minimum-connection-count></proxool></something-else-entirely>


由于proxool必须先启动,所以需要添加1个类,把proxool在web.xml定义为Listener

package cn.wt.Listener;     import java.io.file;   import java.util.Enumeration;   import java.util.PropertIEs;     import javax.servlet.ServletContext;   import javax.servlet.ServletContextEvent;   import javax.servlet.servletcontextlistener;     import org.apache.commons.logging.Log;   import org.apache.commons.logging.LogFactory;   import org.logicalcobwebs.proxool.ProxoolException;   import org.logicalcobwebs.proxool.configuration.JAxpconfigurator;   import org.logicalcobwebs.proxool.configuration.PropertyConfigurator;     /*** @author wangtao*/    public class ProxoolListener implements servletcontextlistener   {       private static final Log LOG = LogFactory.getLog(ProxoolListener.class);              private static final String XML_file_PROPERTY = "xmlfile";         private static final String PROPERTY_file_PROPERTY = "propertyfile";         private static final String auto_SHUTDOWN_PROPERTY = "autoShutdown";              @SuppressWarnings("unused")       private boolean autoShutdown = true;              public voID contextDestroyed(ServletContextEvent arg0)        {            System.out.println("destroy database pool....");        }         public voID contextinitialized(ServletContextEvent contextEvent)        {            ServletContext context = contextEvent.getServletContext(); //对应servlet的init方法中ServletConfig.getServletContext()            String appDir = contextEvent.getServletContext().getRealPath("/");            PropertIEs propertIEs = new PropertIEs();              Enumeration names = context.getinitParameternames();           while (names.hasMoreElements()) {                String name = (String) names.nextElement();                String value = context.getinitParameter(name);                 if (name.equals(XML_file_PROPERTY)) {                   try {                        file file = new file(value);                       if (file.isabsolute()) {                            JAxpconfigurator.configure(value,false);                        } else {                            JAxpconfigurator.configure(appDir + file.separator + value,false);                        }                    } catch (ProxoolException e) {                        LOG.error("Problem configuring " + value,e);                    }                } else if (name.equals(PROPERTY_file_PROPERTY)) {                   try {                        file file = new file(value);                       if (file.isabsolute()) {                            PropertyConfigurator.configure(value);                        } else {                            PropertyConfigurator.configure(appDir + file.separator + value);                        }                    } catch (ProxoolException e) {                        LOG.error("Problem configuring " + value,e);                    }                } else if (name.equals(auto_SHUTDOWN_PROPERTY)) {                    autoShutdown = Boolean.valueOf(value).booleanValue();                } else if (name.startsWith("jdbc")) { //此处以前是PropertyConfigurator.PREFIX改为jdbc,因为此源码是0.9.1版本的,与0.9RC3版本有点不一样                    propertIEs.setProperty(name,value);                }            }             if (propertIEs.size() > 0) {               try {                    PropertyConfigurator.configure(propertIEs);                } catch (ProxoolException e) {                    LOG.error("Problem configuring using init propertIEs",e);                }            }        }     }  

然后web.xml

<?xml version="1.0" enCoding="UTF-8"?><web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5"><display-name>Struts Blank</display-name>    <context-param>   <param-name>xmlfile</param-name>   <param-value>WEB-INF/classes/proxool.xml</param-value></context-param><Listener>   <Listener-class>cn.wt.Listener.ProxoolListener</Listener-class></Listener><context-param>	<param-name>contextConfigLocation</param-name>		<param-value>WEB-INF/classes/beans.xml</param-value>	</context-param>   <Listener>        <Listener-class>org.springframework.web.context.ContextLoaderListener</Listener-class>    </Listener>      <filter>    <filter-name>struts2</filter-name>    <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>  </filter>  <filter-mapPing>    <filter-name>struts2</filter-name>    <url-pattern>/*</url-pattern>  </filter-mapPing>    <welcome-file-List>    <welcome-file>login.Jsp</welcome-file>  </welcome-file-List></web-app>

最后是beans.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:context="http://www.springframework.org/schema/context"       xsi:schemaLocation="http://www.springframework.org/schema/beans           http://www.springframework.org/schema/beans/spring-beans-3.0.xsd            http://www.springframework.org/schema/context           http://www.springframework.org/schema/context/spring-context-2.5.xsd">                        <context:annotation-config/>	  <!-- 自动扫描管理Bean,注解方式进行创建 -->	  <context:component-scan base-package="com"/>     <bean ID="dataSource"     >        <property name="driverClassname">         <value>org.logicalcobwebs.proxool.ProxoolDriver</value>             </property>             <property name="url">                 <value>proxool.pool</value>             </property>         </bean>         <bean ID="sessionFactory"             >             <property name="dataSource">                 <ref bean="dataSource" />             </property>             <property name="hibernatePropertIEs">                 <props>                     <prop key="hibernate.dialect">                        org.hibernate.dialect.sqlServerDialect                   </prop>                     <prop key="hibernate.connection.autocommit">true</prop>                     <prop key="hibernate.show_sql">true</prop>                     <prop key="hibernate.connection.release_mode">                          after_statement                      </prop>                 </props>             </property>         </bean>     </beans>   

由于第1次配置,所以有错请指出...

还有1种,在网络上找到的说法,本人没试过

proxool:关于这个连接池,网上说的例子也有很多,说是性能最好的一个连接池,坑爹的是,网上讲的它跟spring的整合,有很多都是不对的,直接通过spring配置就可以了,没有必要像网上说的,把Listener,改成servlet,直接通过spring的bean配置就可以了,这个在网也有很多。关于这个连接池,我在测试时,发现默认情况下,是不会自动重连的,需要通过如下配置:                                <bean ID="dataSource" >
    <property name="driverClassname" value="org.logicalcobwebs.proxool.ProxoolDriver" />
      <property name="url" value="xxxx.xml" />
</bean> 在xxxx.xml里配置                                                                     <proxool>
    <alias>pool</alias>
    <driver-url>jdbc:MysqL://192.168.1.4:3306/MIGRATE_TEST?characterEnCoding=utf- 8&autoReconnect=true</driver-url>
    <driver-class>com.MysqL.jdbc.Driver</driver-class>
    <driver-propertIEs>
        <property name="user" value="website" />
        <property name="password" value="website" />
        <property name="autoReconnect" value="true" />
    </driver-propertIEs>
    <minimum-connection-count>1</minimum-connection-count>
    <maximum-connection-count>8</maximum-connection-count>
    <prototype-count>1</prototype-count>
    <test-before-use>true</test-before-use>
    <house-keePing-sleep-time>60000</house-keePing-sleep-time>
</proxool> MysqL的URL的后面要加上autoReconnect=true,值得注意的是,当使用ibatis时,日志会报warn:registered a statement as closed which wasn't kNown to be open. 那是因为在ibatis @H_507_403@@H_281_404@      package org.springframework.orm.ibatis;
   public class sqlMapClIEntTemplate extends JdbcAccessor implements sqlMapClIEntoperations {
 public <T> T execute(sqlMapClIEntCallback<T> action) throws DataAccessException {
         ..........
         finally {
            // Only close sqlMapSession if we kNow we've actually opened it
            // at the present level.
            if (ibatisCon == null) {
                session.close();// 由这段引起的,池ibatisCon不为空时,session永远不会关闭

            }

        }
         }
 }
      将红色部分改为 if (ibatisCon != null),就行了

好了,废话不多说了,需要更详细的资料,可以下载源代码,可以到http://download.csdn.net/detail/qq435967718/4738630下载

数据库到http://download.csdn.net/detail/qq435967718/4757430下载(我也不想分开放,不过上次忘记发了,所以补充上去的,1分,也不贵)

.网站经过tomcat发布后,可以访问这个地址(http://localhost:8080/项目名/index1)或(http://localhost:8080/Tour_Struts9//index1),忘记了,自己2个都试试吧,然后导航点击“用户管理”,再点击“网络管理员”,他就把数据库里的数据拿出来了。

总结

以上是内存溢出为你收集整理的(绝对有效)sqlserver2000链接proxool连接池,终于配置出spring整合struts,hibernate annotation(pool数据池,sqlserver2000数据库)全部内容,希望文章能够帮你解决(绝对有效)sqlserver2000链接proxool连接池,终于配置出spring整合struts,hibernate annotation(pool数据池,sqlserver2000数据库)所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/1177569.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-02
下一篇 2022-06-02

发表评论

登录后才能评论

评论列表(0条)

保存