Home > Database > Mysql Tutorial > SSH2+proxool 出现No suitable driver found for proxool.mysqlP

SSH2+proxool 出现No suitable driver found for proxool.mysqlP

WBOY
Release: 2016-06-07 15:26:41
Original
1287 people have browsed it

首先我们要明确使用的是SSH2框架,然而Struts2是基于filter实现的那么在启动proxool的时候就不能够在用servlet来启动了! 于是我们就想到在初始化web容器的时候怎么让他一开始就加载呢? 我们查看tomcat的启动信息: Starting Servlet Engine: Apache Tomcat

首先我们要明确使用的是SSH2框架,然而Struts2是基于filter实现的那么在启动proxool的时候就不能够在用servlet来启动了!

于是我们就想到在初始化web容器的时候怎么让他一开始就加载呢?

我们查看tomcat的启动信息:

 Starting Servlet Engine: Apache Tomcat/6.0.13
2012-6-10 15:31:41 org.apache.catalina.core.ApplicationContext log
信息: Initializing Spring root WebApplicationContext
2012-6-10 15:31:41 org.springframework.web.context.ContextLoader initWebApplicationContext
信息: Root WebApplicationContext: initialization started

最先启动的是spring容器,那么这样我们就可以将proxool的配置写在spring的配置文件中让它最先加载

如下:

	<bean id="dataSource" class="org.logicalcobwebs.proxool.ProxoolDataSource">  
		<property name="alias" value="mysqlProxool"></property>
		<property name="driver" value="com.mysql.jdbc.Driver"></property>
		<property name="driverUrl" value="jdbc:mysql://localhost:3306/my_blog_01?characterEncoding=UTF-8"></property>
		<property name="user" value="root"></property>
		<property name="password" value="123456"></property>
		<property name="minimumConnectionCount" value="2"></property>
		<property name="maximumConnectionCount" value="10"></property>
		<property name="prototypeCount" value="5"></property>
		<!-- <property name="houseKeepingSleepTime" value="100000"/> -->
         	</bean>
Copy after login

这样只需要在sessionFactory加上dataSource的引用即可如下:

 	<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
          		<property name="configLocation" value="classpath:Hibernate.cfg.xml"></property>
          		<span><property name="dataSource">
          			<ref local="dataSource"></ref>
          		</property>
</span>           </bean>
Copy after login

这样就不在需要配置proxool的servlet启动了,例如:

  <servlet>   
        <servlet-name>ServletConfigurator</servlet-name>   
        <servlet-class>   
            org.logicalcobwebs.proxool.configuration.ServletConfigurator   
        </servlet-class>   
        <init-param>   
            <param-name>xmlFile</param-name>   
            <param-value>WEB-INF/classes/proxool.xml</param-value>   
        </init-param>   
        <load-on-startup>1</load-on-startup>   
  </servlet>
 
Copy after login
以上的配置就不在需要在web.xml中进行配置。
Copy after login
而在hibernate.cfg.xml中也不在需要proxool的配置只是配置一些hibernate的信息例如:
Copy after login
<pre class="brush:php;toolbar:false">	<property name="show_sql">true</property>
	<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
Copy after login
和一些实体类的映射文件:
Copy after login
 <mapping resource="com/wuda/hibernate/table/users.hbm.xml"></mapping>
Copy after login
以上就将SSH2+PROXOOL的环境搭建好了。
Copy after login
 
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
但是在搭建好之后如果我们配置<property name="houseKeepingSleepTime" value="100000"></property>
Copy after login
 
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
 
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
又会提示如下错误:
Copy after login
Invalid property 'houseKeepingSleepTime' of bean class [org.logicalcobwebs.proxool.ProxoolDataSource]: Bean property 'houseKeepingSleepTime' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
Copy after login
大概意思是说'houseKeepingSleepTime'属性是不能够写的或者没有合适的setter方法。在他的参数setter和getter的返回结果类型不一致所导致的。
Copy after login
这个我想也正是他的bug吧。
Copy after login
那么具体解决如下:
Copy after login
在proxool-0.9.1.jar(我用的proxool架包)中找到org.logicalcobwebs.proxool.ProxoolDataSource将其源码修改如下:
Copy after login
 
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
源码是:
Copy after login
1./**  
2.    * @see ConnectionPoolDefinitionIF#getHouseKeepingSleepTime  
3.    */  
4.   public long getHouseKeepingSleepTime() {   
5.       return houseKeepingSleepTime;   
6.   }   
7.  
8.   /**  
9.    * @see ConnectionPoolDefinitionIF#getHouseKeepingSleepTime  
10.    */  
11.   public void setHouseKeepingSleepTime(int houseKeepingSleepTime) {   
12.       this.houseKeepingSleepTime = houseKeepingSleepTime;   
13.   }  
Copy after login
Copy after login
Copy after login
 
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
修改为:
Copy after login
<ol>
<li><span><span>/** </span> </span></li>
<li><span><span>    * @see ConnectionPoolDefinitionIF#getHouseKeepingSleepTime </span> </span></li>
<li><span><span>    */</span><span>  </span></span></li>
<li>
<span>   </span><span>public</span><span> </span><span>long</span><span> getHouseKeepingSleepTime() {   </span>
</li>
<li>
<span>       </span><span>return</span><span> houseKeepingSleepTime;   </span>
</li>
<li><span>   }   </span></li>
<li><span>  </span></li>
<li>
<span>   </span><span>/** </span> </li>
<li><span><span>    * @see ConnectionPoolDefinitionIF#getHouseKeepingSleepTime </span> </span></li>
<li><span><span>    *此处将int类型改为long类型 </span> </span></li>
<li><span><span>    */</span><span>  </span></span></li>
<li>
<span>   </span><span>public</span><span> </span><span>void</span><span> setHouseKeepingSleepTime(</span><span>long</span><span> houseKeepingSleepTime) {   </span>
</li>
<li>
<span>       </span><span>this</span><span>.houseKeepingSleepTime = houseKeepingSleepTime;   </span>
</li>
<li><span>   }  </span></li>
</ol>
Copy after login
这样所有问题都解决!
Copy after login
以上所有步骤都是通过本人在网上查资料,自己手动配置而成。验证通过!
Copy after login
 
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
 
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
 
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template